0001 function ltpdagui(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
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, setappdata(0,'startup',1); [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
0060 foregroundcolor = [0.2,0.2,0.2];
0061
0062 backgroundcolor = [0.7,0.7,1];
0063
0064 panelbackgroundcolor = [0.98,0.98,0.98];
0065
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
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
0106 TopBottomTabCbk([],[],1,1)
0107 active = 1;
0108 return
0109 end
0110 if value == 1.1
0111 TopBottomTabCbk([],[],1,1)
0112 active = 1;
0113 runSim = 1;
0114 end
0115 if value == 2
0116 TopBottomTabCbk([],[],1,2)
0117 active = 1;
0118 return
0119 end
0120 if value == 6
0121 TopBottomTabCbk([],[],3,3)
0122 active = 1;
0123 return
0124 end
0125 if value == 8
0126 TopBottomTabCbk([],[],2,2)
0127 active = 1;
0128 return
0129 end
0130
0131 case 'callback'
0132 if value==1 && strcmp(bdroot,'ltpda_library')
0133 HelpCallback();
0134 return;
0135 end
0136 if value==1 && isempty(findobj('Name',tabbedFigName))
0137 return;
0138 end
0139 otherwise
0140 eval([property '= ' value ';']);
0141 end
0142 end
0143
0144 parent = findobj('Name',tabbedFigName);
0145 if ~isempty(parent), clf(parent); set(parent,'Resize','on','ResizeFcn',{@GUIResize,guiSize});
0146 else parent = figure('Position',guiSize,'Name',tabbedFigName,'Resize','on','ResizeFcn',{@GUIResize,guiSize},'NumberTitle','off','Toolbar','none','Menubar','none');
0147 end
0148
0149 set(parent,'Tag','LTPDAGUI','NextPlot','new');
0150
0151 if ~exist('margins','var'), margins = {1,'pixels'}; end
0152 if ~iscell(margins), margins = {margins,units}; end
0153 if ~exist('bordertype','var'), bordertype = 'none'; end
0154 if ~exist('titlebackgroundcolor','var'), titlebackgroundcolor = 0.95*panelbackgroundcolor; end
0155 if ~active, active = 1; end
0156
0157 clear htab
0158 htab = uipanel( ...
0159 'Parent',parent, ...
0160 'Units',units, ...
0161 'Position',position, ...
0162 'BackgroundColor',backgroundcolor, ...
0163 'BorderType',bordertype, ...
0164 'Visible','on', ...
0165 'Tag',tag);
0166
0167 set(htab,'Units','pixels');
0168 tabpos = get(htab,'Position');
0169
0170
0171 status = uicontainer( ...
0172 'Parent',htab, ...
0173 'BackgroundColor',backgroundcolor, ...
0174 'Units',margins{2}, ...
0175 'Position',[1,1,1,1], ...
0176 'Visible','off');
0177
0178 set(status,'Units','pixels');
0179 charsz = get(status,'Position');
0180
0181 margins = [charsz(1:2),charsz(1:2)].*margins{1};
0182 set(status,'Units','characters');
0183 set(status,'Position',[1,1,1,1]);
0184 set(status,'Units','pixels');
0185 charsz = get(status,'Position');
0186 titleheight = 1.6*charsz(4);
0187 titleheight = titleheight*scaleX;
0188
0189 margins(3:4) = -(margins(1:2)+margins(3:4));
0190 [loop,sign] = deal(1:ntab,[1,ntab,1,0]);
0191
0192 addtitle = 2*[sign(3:4),-1,-1];
0193 ttextpos = [0.05,0.08,0.9,0.76];
0194
0195 for kk=1:ntab
0196 title(kk) = uipanel( ...
0197 'Parent',htab, ...
0198 'Units','pixels', ...
0199 'BackgroundColor',titlebackgroundcolor, ...
0200 'BorderType','beveledout', ...
0201 'ButtonDownFcn',{@TopBottomTabCbk,kk,1}, ...
0202 'Visible','on');
0203
0204 ttext(kk) = uicontrol( ...
0205 'Parent',title(kk), ...
0206 'Units','normalized', ...
0207 'Position',ttextpos, ...
0208 'ForegroundColor',foregroundcolor, ...
0209 'BackgroundColor',titlebackgroundcolor, ...
0210 'HorizontalAlignment',horizontalalignment, ...
0211 'Style','text', ...
0212 'String',string{kk}, ...
0213 'FontSize',8*scaleX,...
0214 'Enable','inactive', ...
0215 'HitTest','off',...
0216 'Visible','on');
0217
0218 end
0219
0220 set(htab,'Units','pixels');
0221 dimension = get(htab,'Position');
0222 dimension(4) = dimension(4)-nrows*titleheight+5;
0223 panel = uipanel('Parent',htab,'Units','pixels','Position',dimension,'BackgroundColor',panelbackgroundcolor,'BorderType','beveledout','Visible','on');
0224
0225 dimension = get(htab,'Position');
0226 logosize = [52,52];
0227 dimension = [dimension(3)-logosize(1)-3 , dimension(4)-logosize(2) , logosize];
0228 logo = axes('Parent',htab,'Units','pixels','Position',dimension,'Tag','Logo');
0229 image(imread('iconltp.jpg'),'Parent',logo,'AlphaData',imread('iconltpalpha.gif'));
0230 axis(logo,'off'); axis(logo,'square');
0231 set(logo,'HandleVisibility','callback');
0232
0233 dimension = get(htab,'Position');
0234 logosize = [40 40];
0235 dimension = [dimension(3)-logosize(1)-70 , dimension(4)-logosize(2)-9 , logosize];
0236 start2 = axes('Parent',htab,'Units','pixels','Position',dimension,'Tag','Start2');
0237 image(imread('startgreen.jpg'),'Parent',start2,'AlphaData',imread('startalpha.gif'),'ButtonDownFcn','ltpdagui(''redraw'',1.1);','Tag','StartButton');
0238 axis(start2,'off');
0239 set(start2,'HandleVisibility','callback');
0240
0241 if active>ntab, active=ntab; end
0242
0243 inset(1) = uicontrol( ...
0244 'Parent',htab, ...
0245 'Units','pixels', ...
0246 'BackgroundColor',panelbackgroundcolor, ...
0247 'Style','text', ...
0248 'Visible','on');
0249 if ~isnan(titlehighlightcolor)
0250 inset(2) = uicontrol( ...
0251 'Parent',htab, ...
0252 'Units','pixels', ...
0253 'BackgroundColor',titlehighlightcolor, ...
0254 'Style','text', ...
0255 'Visible','on');
0256 inset(3) = uicontrol( ...
0257 'Parent',htab, ...
0258 'Units','pixels', ...
0259 'BackgroundColor',0.85*titlehighlightcolor, ...
0260 'Style','text', ...
0261 'Visible','on');
0262 end
0263
0264
0265
0266 for xx=2:nrows
0267 localString = labels{xx};
0268 ntab = numel(localString);
0269 for tt=1:ntab
0270 titles(xx,tt) = uipanel( ...
0271 'Parent',htab, ...
0272 'Units','pixels', ...
0273 'BackgroundColor',titlebackgroundcolor, ...
0274 'BorderType','beveledout', ...
0275 'ButtonDownFcn',{@TopBottomTabCbk,tt,xx}, ...
0276 'Visible','on');
0277
0278 uicontrol( ...
0279 'Parent',titles(xx,tt), ...
0280 'Units','normalized', ...
0281 'Position',ttextpos, ...
0282 'ForegroundColor',foregroundcolor, ...
0283 'BackgroundColor',titlebackgroundcolor, ...
0284 'HorizontalAlignment',horizontalalignment, ...
0285 'Style','text', ...
0286 'String',localString{tt}, ...
0287 'Enable','inactive', ...
0288 'FontSize',8*scaleX,...
0289 'HitTest','off',...
0290 'Visible','on');
0291
0292 end
0293 end
0294
0295
0296 TopBottomTabResizeCbk();
0297
0298 panelTitle = get(ttext(active),'string');
0299 setappdata(0, 'ltpda_currPanel', panel);
0300
0301
0302
0303
0304 CheckTimerAlive()
0305
0306 switch panelTitle
0307 case 'Main LTPDA panel'
0308 if exist('runSim','var') && runSim==1
0309 runSim = 0;
0310 pan1main(panel,1)
0311 else pan1main(panel)
0312 end
0313 case 'Parameters'
0314 pan2param(panel)
0315 case 'Repository'
0316 pan3repo(panel)
0317 case 'Import from workspace'
0318 pan4import(panel)
0319 case 'Output'
0320 pan5output(panel)
0321 case 'Globals'
0322 pan6globals(panel)
0323 case 'Partial execution'
0324 pan7partial(panel)
0325 case 'Nested loops'
0326 panXyettocome(panel)
0327
0328
0329 end
0330
0331
0332
0333
0334
0335
0336
0337
0338 function TopBottomTabCbk(hobj,evdt,indx,numbrow)
0339
0340
0341 if numbrow>1
0342 for pp=ntab:-1:1, ntab = ntab - strcmp(string(pp),''); end
0343 if ntab==1, active=1; end
0344
0345
0346 temp = labels(1);
0347 labels(1) = labels(numbrow);
0348 labels(numbrow) = temp;
0349 clear temp
0350
0351 for ii=1:nrows
0352 temp(ii,1:numel(labels{ii}))=labels{ii};
0353 end
0354 else
0355 active = indx;
0356 for ii=1:nrows
0357 temp(ii,1:numel(labels{ii}))=labels{ii};
0358 end
0359 end
0360
0361
0362 ltpdagui('title',temp,'active',indx);
0363
0364
0365 end
0366
0367
0368
0369 function TopBottomTabResizeCbk(varargin)
0370
0371
0372 units = get(htab,'Units');
0373 set(htab,'Units','pixels');
0374 tabpos = get(htab,'Position');
0375 tabpos(3) = tabpos(3)*0.85;
0376 set(htab,'Units',units);
0377 ntab = numel(string);
0378 for oo=ntab:-1:1, ntab = ntab - strcmp(string(oo),''); end
0379
0380 titlepos = [0,0,0,titleheight];
0381 panelpos = [0,0,tabpos(3),tabpos(4)-titleheight]+margins;
0382 titlepos(2) = panelpos(2)+panelpos(4);
0383 panelpos(2) = panelpos(2)-titleheight*(nrows-1)+6;
0384
0385 n = sum(cellfun('length',string))+2*ntab;
0386 titlepos(1) = panelpos(1)+(1-sign(3))*panelpos(3);
0387 upperpos = titlepos(2);
0388 for k=loop
0389 titlepos(3) = panelpos(3)*(length(string{k})+2)/n;
0390 addtopos = addtitle.*[k==1,1,k==1|k==ntab,1];
0391 titlepos(1) = titlepos(1)-(1-sign(3))*titlepos(3);
0392 titlepos(2) = upperpos - titlepos(4)*(nrows-1)+3+1;
0393 set(title(k),'Position',titlepos+addtopos);
0394 titlepos(1) = titlepos(1)+sign(3)*titlepos(3);
0395 end
0396
0397
0398
0399 if nrows>1
0400 for xxx=2:nrows
0401 localString = labels{xxx};
0402 ntab = numel(localString);
0403 for i=ntab:-1:1, ntab = ntab - strcmp(localString(i),''); end
0404 n = sum(cellfun('length',localString))+2*ntab;
0405 titlepos(1) = panelpos(1)+(1-sign(3))*panelpos(3);
0406 titlepos(2) = titlepos(2) + titlepos(4)-2;
0407 for k=1:ntab
0408 titlepos(3) = panelpos(3)*(length(localString{k})+2)/n;
0409 addtopos = addtitle.*[k==1,1,k==1|k==ntab,1];
0410 titlepos(1) = titlepos(1)-(1-sign(3))*titlepos(3);
0411 if ntab==1, titlepos(3)=titlepos(3)-2; end
0412 set(titles(xxx,k),'Position',titlepos+addtopos);
0413 titlepos(1) = titlepos(1)+sign(3)*titlepos(3);
0414 end
0415 if ntab<numel(localString)
0416 for qq=ntab+1:numel(localString)
0417 nullpos=[0,0,1,1];
0418 set(titles(xxx,qq),'Position',nullpos);
0419 end
0420 end
0421 end
0422 end
0423
0424
0425
0426 titlepos = get(title(active),'Position');
0427 titlepos = titlepos-addtitle.*[active==sign(1),1,active==sign(1),1];
0428 titlepos(3) = titlepos(3)-addtitle(3)*(active==sign(2));
0429 ntab = numel(string);
0430 for i=ntab:-1:1, ntab = ntab - strcmp(string(i),''); end
0431 if ntab==1, titlepos(3) = titlepos(3)-4; end
0432
0433 set(title(active),'Position',titlepos,'BackgroundColor',panelbackgroundcolor);
0434 set(ttext(active),'FontWeight','bold','BackgroundColor',panelbackgroundcolor);
0435
0436 insetpos = [titlepos(1)+1,titlepos(2)+sign(4)*titlepos(4)-2,titlepos(3)-1,3];
0437 set(inset(1),'Position',insetpos);
0438 try
0439 insetpos = insetpos+[0,(1-2*sign(4))*titleheight+2*sign(4),0,-2];
0440 set(inset(2),'Position',insetpos);
0441 set(inset(3),'Position',insetpos+[2,1-2*sign(4),-4,0]);
0442 catch
0443 end
0444 end
0445
0446
0447
0448 function GUIResize(varargin)
0449
0450
0451 guiSize = varargin{3};
0452 newSize = get(findobj('Tag','LTPDAGUI'),'Position');
0453
0454
0455 if newSize(3)<guiSize(3), newSize(3)=guiSize(3); end
0456
0457 if newSize(4)<guiSize(4), newSize(4)=guiSize(4); end
0458
0459 screenSize = get(0,'screensize');
0460 if newSize(2)+newSize(4)+30>screenSize(4), newSize(2)=screenSize(4)-newSize(4)-40; end
0461 if newSize(1)+newSize(3)>screenSize(3), newSize(1)=screenSize(3)-newSize(3)-5; end
0462
0463 set(findobj('Tag','LTPDAGUI'),'Position',newSize);
0464
0465
0466 pause(0.1)
0467 if ~getappdata(0,'startup'), TopBottomTabCbk([],[],active,1)
0468 else setappdata(0,'startup',0);
0469 end
0470
0471 end
0472
0473
0474
0475
0476 function CheckTimerAlive(varargin)
0477
0478
0479
0480 alltimers = timerfindall;
0481 if strcmp(get(alltimers(1),'Running'),'off')
0482 start(alltimers(1))
0483 end
0484 end
0485
0486
0487
0488 function HelpCallback(varargin)
0489
0490
0491
0492 try
0493 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
0494 functionname = get_param(childpath,'Tag');
0495
0496 description = get_param(gcbh,'Description');
0497 funcname = findstr('functionName=',description);
0498 if funcname
0499 i = funcname+14;
0500 while ~strcmp(description(i),';'), i=i+1; end
0501 functionname = description(funcname+14:i-2);
0502 end
0503
0504 [func,classes] = strtok(get(gcbh,'Tag'));
0505 if strcmp(func,'method')
0506 helptext = help([strtrim(classes),'/',functionname]);
0507 else
0508 helptext = help(functionname);
0509 end
0510
0511 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'));
0512
0513 uicontrol('Parent',helpFigure,'Units','normalized','HorizontalAlignment','left','Position',[0 0 1 1],'FontSize',8,'String',helptext,'Visible','on','max',100,'Style','edit');
0514 catch
0515 end
0516 end
0517
0518
0519 end