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