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