Mercurial > hg > ltpda
comparison m-toolbox/m/gui/gltpda/ltpdagui.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 function ltpdagui(varargin) | |
2 | |
3 % ========================================================================= | |
4 % LTPDA GUI | |
5 % ========================================================================= | |
6 % | |
7 % Open the main LTPDA GUI. | |
8 % | |
9 % $Id: ltpdagui.m,v 1.27 2009/01/23 12:40:51 nicola Exp $ | |
10 | |
11 warning off all | |
12 global LTPDAinvar LTPDAoutvar active labels scaleX | |
13 | |
14 tabbedFigName = 'Family GUI'; | |
15 screenSize = get(0,'screensize'); | |
16 scaleX = screenSize(3)/1280; | |
17 if scaleX<1, scaleX = 1; end | |
18 setappdata(0, 'ltpda_gui_scalefactor',scaleX); | |
19 guiSize = [1 1 600*scaleX 550*scaleX]; | |
20 guiSize = round([(screenSize(3)-guiSize(3))/2 , (screenSize(4)-guiSize(4))/2 , guiSize(3) , guiSize(4)]); | |
21 | |
22 if ~isempty(findobj('Tag','LTPDAGUI')) && nargin==0, return; end | |
23 | |
24 if isempty(LTPDAinvar), LTPDAinvar = {}; end | |
25 if isempty(LTPDAoutvar), LTPDAoutvar = {}; end | |
26 | |
27 userID = getappdata(0,'ltpda_repo_user'); | |
28 if isempty(userID), userID = ''; end | |
29 passwd = getappdata(0,'ltpda_repo_pass'); | |
30 if isempty(passwd), passwd = ''; end | |
31 | |
32 if nargin==0, setappdata(0,'startup',1); [userID passwd] = utils.mysql.logindlg(userID,'',1,tabbedFigName,guiSize); try cd(getappdata(0,'DefaultDataDirectory')); catch, end; end | |
33 if isempty(userID), userID = 'JohnDoe'; passwd=''; end | |
34 | |
35 setappdata(0,'ltpda_repo_user',userID) | |
36 setappdata(0,'ltpda_repo_pass',passwd) | |
37 | |
38 if nargin==0 | |
39 clc | |
40 disp('Please wait: starting LTPDA GUI...') | |
41 disp('Loading Simulink...') | |
42 drawnow | |
43 load_system('simulink') | |
44 load_system('ltpda_library') | |
45 end | |
46 | |
47 try stop(timerfindall); delete(timerfindall); catch end | |
48 t1 = timer('TimerFcn',@CheckTimerAlive,'ExecutionMode','fixedRate','Period',0.3); | |
49 t2 = timer('TimerFcn',@CheckTimerAlive,'ExecutionMode','fixedRate','Period',1); | |
50 start(t1) | |
51 start(t2) | |
52 | |
53 %% | |
54 | |
55 tag = ''; | |
56 units = 'normalized'; | |
57 position = [0,0,1,1]; | |
58 | |
59 % text color in the label: | |
60 foregroundcolor = [0.2,0.2,0.2]; | |
61 % color in the background, behind tabs: | |
62 backgroundcolor = [0.7,0.7,1]; | |
63 % background color, inside every tab: | |
64 panelbackgroundcolor = [0.98,0.98,0.98]; | |
65 % color of the small highlight line, above the selected tab | |
66 titlehighlightcolor = [1,0.3,0]; | |
67 | |
68 horizontalalignment = 'center'; | |
69 | |
70 active = 0; | |
71 string = {'Main LTPDA panel','Parameters','Output','';'Repository','Partial execution','Nested loops','Globals'}; | |
72 nrows = size(string,1); | |
73 if nrows>1 | |
74 for nn=1:nrows, labels{nn} = string(nn,:); end | |
75 string = string(1,:); | |
76 end | |
77 ntab = numel(string); | |
78 for jj=ntab:-1:1, ntab = ntab - strcmp(string(jj),''); end | |
79 | |
80 % Cycle to retrieve parameters from the user: | |
81 for mm=1:2:nargin | |
82 property = lower(varargin{mm}); | |
83 value = varargin{mm+1}; | |
84 switch property | |
85 case {'title','string'} | |
86 string = value; | |
87 nrows = size(string,1); | |
88 if nrows>1 | |
89 for nn=1:nrows, labels{nn} = string(nn,:);end | |
90 string = string(1,:); | |
91 end | |
92 ntab = numel(string); | |
93 for jj=ntab:-1:1, ntab = ntab - strcmp(string(jj),''); end | |
94 case {'frameposition','position'} | |
95 position = value; | |
96 case {'framebackgroundcolor','backgroundcolor'} | |
97 backgroundcolor = value; | |
98 case {'framebordertype','bordertype'} | |
99 bordertype = value; | |
100 case {'titleforegroundcolor','foregroundcolor'} | |
101 foregroundcolor = value; | |
102 case {'selecteditem','active'} | |
103 active = value; | |
104 case 'redraw' | |
105 if value == 1 % main panel | |
106 TopBottomTabCbk([],[],1,1) | |
107 active = 1; | |
108 return | |
109 end | |
110 if value == 1.1 % the user clicked the Start button | |
111 TopBottomTabCbk([],[],1,1) | |
112 active = 1; | |
113 runSim = 1; | |
114 end | |
115 if value == 2 % Parameters panel | |
116 TopBottomTabCbk([],[],2,1) | |
117 active = 1; | |
118 return | |
119 end | |
120 if value == 6 % globals panel | |
121 TopBottomTabCbk([],[],4,2) | |
122 active = 1; | |
123 return | |
124 end | |
125 if value == 8 % nested loops | |
126 TopBottomTabCbk([],[],3,2) | |
127 active = 1; | |
128 return | |
129 end | |
130 | |
131 case 'callback' | |
132 if value==1 && strcmp(bdroot,'ltpda_library') | |
133 HelpCallback(); | |
134 return; | |
135 end | |
136 if value==1 && isempty(findobj('Name',tabbedFigName)) | |
137 return; | |
138 end | |
139 otherwise | |
140 eval([property '= ' value ';']); | |
141 end | |
142 end | |
143 | |
144 parent = findobj('Tag','LTPDAGUI'); | |
145 if ~isempty(parent), clf(parent); set(parent,'Resize','on','ResizeFcn',{@GUIResize,guiSize}); | |
146 else parent = figure('Position',guiSize,'Name',tabbedFigName,'Resize','on','ResizeFcn',{@GUIResize,guiSize},'NumberTitle','off','Toolbar','none','Menubar','none'); | |
147 end | |
148 | |
149 set(parent,'Tag','LTPDAGUI','NextPlot','new'); | |
150 | |
151 if ~exist('margins','var'), margins = {1,'pixels'}; end | |
152 if ~iscell(margins), margins = {margins,units}; end | |
153 if ~exist('bordertype','var'), bordertype = 'none'; end | |
154 if ~exist('titlebackgroundcolor','var'), titlebackgroundcolor = 0.95*panelbackgroundcolor; end | |
155 if ~active, active = 1; end | |
156 | |
157 clear htab | |
158 htab = uipanel( ... | |
159 'Parent',parent, ... | |
160 'Units',units, ... | |
161 'Position',position, ... | |
162 'BackgroundColor',backgroundcolor, ... | |
163 'BorderType',bordertype, ... | |
164 'Visible','on', ... | |
165 'Tag',tag); | |
166 | |
167 set(htab,'Units','pixels'); | |
168 tabpos = get(htab,'Position'); | |
169 | |
170 | |
171 status = uicontainer( ... | |
172 'Parent',htab, ... | |
173 'BackgroundColor',backgroundcolor, ... | |
174 'Units',margins{2}, ... | |
175 'Position',[1,1,1,1], ... | |
176 'Visible','off'); | |
177 | |
178 set(status,'Units','pixels'); | |
179 charsz = get(status,'Position'); | |
180 | |
181 margins = [charsz(1:2),charsz(1:2)].*margins{1}; | |
182 set(status,'Units','characters'); | |
183 set(status,'Position',[1,1,1,1]); | |
184 set(status,'Units','pixels'); | |
185 charsz = get(status,'Position'); | |
186 titleheight = 2.4*charsz(4); | |
187 titleheight = titleheight*scaleX; | |
188 | |
189 margins(3:4) = -(margins(1:2)+margins(3:4)); | |
190 [loop,sign] = deal(1:ntab,[1,ntab,1,0]); | |
191 | |
192 addtitle = 2*[sign(3:4),-1,-1]; | |
193 ttextpos = [0.05,0.08,0.9,0.76]; | |
194 | |
195 for kk=1:ntab | |
196 title(kk) = uipanel( ... | |
197 'Parent',htab, ... | |
198 'Units','pixels', ... | |
199 'BackgroundColor',titlebackgroundcolor, ... | |
200 'BorderType','beveledout', ... | |
201 'ButtonDownFcn',{@TopBottomTabCbk,kk,1}, ... | |
202 'Visible','on'); | |
203 | |
204 ttext(kk) = uicontrol( ... | |
205 'Parent',title(kk), ... | |
206 'Units','normalized', ... | |
207 'Position',ttextpos, ... | |
208 'ForegroundColor',foregroundcolor, ... | |
209 'BackgroundColor',titlebackgroundcolor, ... | |
210 'HorizontalAlignment',horizontalalignment, ... | |
211 'Style','text', ... | |
212 'String',string{kk}, ... | |
213 'FontSize',11*scaleX,... | |
214 'Enable','inactive', ... | |
215 'HitTest','off',... | |
216 'Visible','on'); | |
217 | |
218 end | |
219 | |
220 set(htab,'Units','pixels'); | |
221 dimension = get(htab,'Position'); | |
222 dimension(4) = dimension(4)-nrows*titleheight+5; | |
223 panel = uipanel('Parent',htab,'Tag','mainPanel','Units','pixels','Position',dimension,'BackgroundColor',panelbackgroundcolor,'BorderType','beveledout','Visible','on'); | |
224 | |
225 dimension = get(htab,'Position'); | |
226 logosize = [52,52]; | |
227 dimension = [dimension(3)-logosize(1)-3 , dimension(4)-logosize(2) , logosize]; | |
228 logo = axes('Parent',htab,'Units','pixels','Position',dimension,'Tag','Logo'); | |
229 image(imread('iconltp.jpg'),'Parent',logo,'AlphaData',imread('iconltpalpha.gif'),'ButtonDownFcn','try open_system(gcs); catch, end;'); | |
230 axis(logo,'off'); axis(logo,'square'); | |
231 set(logo,'HandleVisibility','callback'); | |
232 | |
233 dimension = get(htab,'Position'); | |
234 logosize = [40 40]; | |
235 dimension = [dimension(3)-logosize(1)-70 , dimension(4)-logosize(2)-9 , logosize]; | |
236 start2 = axes('Parent',htab,'Units','pixels','Position',dimension,'Tag','Start2'); | |
237 image(imread('startgreen.jpg'),'Parent',start2,'AlphaData',imread('startalpha.gif'),'ButtonDownFcn','ltpdagui(''redraw'',1.1);','Tag','StartButton'); | |
238 axis(start2,'off'); | |
239 set(start2,'HandleVisibility','callback'); | |
240 | |
241 if active>ntab, active=ntab; end | |
242 | |
243 inset(1) = uicontrol( ... | |
244 'Parent',htab, ... | |
245 'Units','pixels', ... | |
246 'BackgroundColor',panelbackgroundcolor, ... | |
247 'Style','text', ... | |
248 'Visible','on'); | |
249 if ~isnan(titlehighlightcolor) | |
250 inset(2) = uicontrol( ... | |
251 'Parent',htab, ... | |
252 'Units','pixels', ... | |
253 'BackgroundColor',titlehighlightcolor, ... | |
254 'Style','text', ... | |
255 'Visible','on'); | |
256 inset(3) = uicontrol( ... | |
257 'Parent',htab, ... | |
258 'Units','pixels', ... | |
259 'BackgroundColor',0.85*titlehighlightcolor, ... | |
260 'Style','text', ... | |
261 'Visible','on'); | |
262 end | |
263 | |
264 % ======================================================================= | |
265 % OTHER BUTTONS | |
266 for xx=2:nrows | |
267 localString = labels{xx}; | |
268 ntab = numel(localString); | |
269 for tt=1:ntab | |
270 titles(xx,tt) = uipanel( ... | |
271 'Parent',htab, ... | |
272 'Units','pixels', ... | |
273 'BackgroundColor',titlebackgroundcolor, ... | |
274 'BorderType','beveledout', ... | |
275 'ButtonDownFcn',{@TopBottomTabCbk,tt,xx}, ... | |
276 'Visible','on'); | |
277 | |
278 uicontrol( ... | |
279 'Parent',titles(xx,tt), ... | |
280 'Units','normalized', ... | |
281 'Position',ttextpos, ... | |
282 'ForegroundColor',foregroundcolor, ... | |
283 'BackgroundColor',titlebackgroundcolor, ... | |
284 'HorizontalAlignment',horizontalalignment, ... | |
285 'Style','text', ... | |
286 'String',localString{tt}, ... | |
287 'Enable','inactive', ... | |
288 'FontSize',11*scaleX,... | |
289 'HitTest','off',... | |
290 'Visible','on'); | |
291 | |
292 end | |
293 end | |
294 % ======================================================================= | |
295 | |
296 TopBottomTabResizeCbk(); | |
297 | |
298 panelTitle = get(ttext(active),'string'); | |
299 setappdata(0, 'ltpda_currPanel', panel); | |
300 | |
301 % ======================================================================= | |
302 % ======================================================================= | |
303 % ======================================================================= | |
304 CheckTimerAlive() | |
305 | |
306 switch panelTitle | |
307 case 'Main LTPDA panel' | |
308 if exist('runSim','var') && runSim==1 | |
309 runSim = 0; %#ok<NASGU> | |
310 pan1main(panel,1) | |
311 else pan1main(panel) | |
312 end | |
313 case 'Parameters' | |
314 pan2param(panel) | |
315 case 'Repository' | |
316 pan3repo(panel) | |
317 case 'Import from workspace' | |
318 pan4import(panel) | |
319 case 'Output' | |
320 pan5output(panel) | |
321 case 'Globals' | |
322 pan6globals(panel) | |
323 case 'Partial execution' | |
324 pan7partial(panel) | |
325 case 'Nested loops' | |
326 % panXyettocome(panel) | |
327 pan8nested(panel) | |
328 | |
329 end | |
330 | |
331 % ======================================================================= | |
332 % ======================================================================= | |
333 % ======================================================================= | |
334 | |
335 | |
336 %% | |
337 %-------------------------------------------------------------------------- | |
338 function TopBottomTabCbk(hobj,evdt,indx,numbrow) %#ok<INUSL> | |
339 % Executed when the user clicks on a another tab or resize. | |
340 | |
341 if numbrow>1 % the user clicked on another row | |
342 for pp=ntab:-1:1, ntab = ntab - strcmp(string(pp),''); end | |
343 if ntab==1, active=1; end | |
344 | |
345 % Swop rows: | |
346 temp = labels(1); | |
347 labels(1) = labels(numbrow); | |
348 labels(numbrow) = temp; | |
349 clear temp | |
350 % Rebuild the proper list: | |
351 for ii=1:nrows | |
352 temp(ii,1:numel(labels{ii}))=labels{ii}; | |
353 end | |
354 else | |
355 active = indx; | |
356 for ii=1:nrows | |
357 temp(ii,1:numel(labels{ii}))=labels{ii}; | |
358 end | |
359 end | |
360 | |
361 % ====================================== | |
362 ltpdagui('title',temp,'active',indx); | |
363 % ====================================== | |
364 | |
365 end | |
366 %-------------------------------------------------------------------------- | |
367 | |
368 %-------------------------------------------------------------------------- | |
369 function TopBottomTabResizeCbk(varargin) | |
370 % Properly draws the panels. | |
371 | |
372 units = get(htab,'Units'); | |
373 set(htab,'Units','pixels'); | |
374 tabpos = get(htab,'Position'); | |
375 tabpos(3) = tabpos(3)-120; | |
376 set(htab,'Units',units); | |
377 ntab = numel(string); | |
378 for oo=ntab:-1:1, ntab = ntab - strcmp(string(oo),''); end | |
379 | |
380 titlepos = [0,0,0,titleheight]; | |
381 panelpos = [0,0,tabpos(3),tabpos(4)-titleheight]+margins; | |
382 titlepos(2) = panelpos(2)+panelpos(4); | |
383 panelpos(2) = panelpos(2)-titleheight*(nrows-1)+6; | |
384 | |
385 n = sum(cellfun('length',string))+2*ntab; | |
386 titlepos(1) = panelpos(1)+(1-sign(3))*panelpos(3); | |
387 upperpos = titlepos(2); | |
388 for k=loop | |
389 titlepos(3) = panelpos(3)*(length(string{k})+2)/n; | |
390 addtopos = addtitle.*[k==1,1,k==1|k==ntab,1]; | |
391 titlepos(1) = titlepos(1)-(1-sign(3))*titlepos(3); | |
392 titlepos(2) = upperpos - titlepos(4)*(nrows-1)+3+1; | |
393 set(title(k),'Position',titlepos+addtopos); | |
394 titlepos(1) = titlepos(1)+sign(3)*titlepos(3); | |
395 end | |
396 | |
397 % ======================================================================= | |
398 | |
399 if nrows>1 | |
400 for xxx=2:nrows | |
401 localString = labels{xxx}; | |
402 ntab = numel(localString); | |
403 for i=ntab:-1:1, ntab = ntab - strcmp(localString(i),''); end | |
404 n = sum(cellfun('length',localString))+2*ntab; | |
405 titlepos(1) = panelpos(1)+(1-sign(3))*panelpos(3); | |
406 titlepos(2) = titlepos(2) + titlepos(4)-2; | |
407 for k=1:ntab | |
408 titlepos(3) = panelpos(3)*(length(localString{k})+2)/n; | |
409 addtopos = addtitle.*[k==1,1,k==1|k==ntab,1]; | |
410 titlepos(1) = titlepos(1)-(1-sign(3))*titlepos(3); | |
411 if ntab==1, titlepos(3)=titlepos(3)-2; end | |
412 set(titles(xxx,k),'Position',titlepos+addtopos); | |
413 titlepos(1) = titlepos(1)+sign(3)*titlepos(3); | |
414 end | |
415 if ntab<numel(localString) | |
416 for qq=ntab+1:numel(localString) | |
417 nullpos=[0,0,1,1]; | |
418 set(titles(xxx,qq),'Position',nullpos); | |
419 end | |
420 end | |
421 end | |
422 end | |
423 | |
424 % ======================================================================= | |
425 | |
426 titlepos = get(title(active),'Position'); | |
427 titlepos = titlepos-addtitle.*[active==sign(1),1,active==sign(1),1]; | |
428 titlepos(3) = titlepos(3)-addtitle(3)*(active==sign(2)); | |
429 ntab = numel(string); | |
430 for i=ntab:-1:1, ntab = ntab - strcmp(string(i),''); end | |
431 if ntab==1, titlepos(3) = titlepos(3)-4; end | |
432 | |
433 set(title(active),'Position',titlepos,'BackgroundColor',panelbackgroundcolor); | |
434 set(ttext(active),'FontWeight','bold','BackgroundColor',panelbackgroundcolor); | |
435 | |
436 insetpos = [titlepos(1)+1,titlepos(2)+sign(4)*titlepos(4)-2,titlepos(3)-1,3]; | |
437 set(inset(1),'Position',insetpos); | |
438 try | |
439 insetpos = insetpos+[0,(1-2*sign(4))*titleheight+2*sign(4),0,-2]; | |
440 set(inset(2),'Position',insetpos); | |
441 set(inset(3),'Position',insetpos+[2,1-2*sign(4),-4,0]); | |
442 catch | |
443 end | |
444 end | |
445 %-------------------------------------------------------------------------- | |
446 | |
447 %-------------------------------------------------------------------------- | |
448 function GUIResize(varargin) | |
449 % Called whenever the user resize the GUI window. | |
450 | |
451 guiSize = varargin{3}; | |
452 newSize = get(findobj('Tag','LTPDAGUI'),'Position'); | |
453 | |
454 % To avoid a width lower than the fixed minimum: | |
455 if newSize(3)<guiSize(3), newSize(3)=guiSize(3); end | |
456 % To avoid an height lower than the fixed minimum: | |
457 if newSize(4)<guiSize(4), newSize(4)=guiSize(4); end | |
458 % To avoid a window moved outside the screen border: | |
459 screenSize = get(0,'screensize'); | |
460 if newSize(2)+newSize(4)+30>screenSize(4), newSize(2)=screenSize(4)-newSize(4)-40; end | |
461 if newSize(1)+newSize(3)>screenSize(3), newSize(1)=screenSize(3)-newSize(3)-5; end | |
462 | |
463 set(findobj('Tag','LTPDAGUI'),'Position',newSize); | |
464 | |
465 % Redraw the GUI on the current panel: | |
466 % pause(0.1) | |
467 if ~getappdata(0,'startup'), TopBottomTabCbk([],[],active,1) | |
468 else setappdata(0,'startup',0); | |
469 end | |
470 | |
471 end | |
472 %-------------------------------------------------------------------------- | |
473 | |
474 %% | |
475 %---------------------------------------------------------------------- | |
476 function CheckTimerAlive(varargin) | |
477 % This is the function to execute a continuous timer check | |
478 | |
479 % Keep alive the first timer: | |
480 alltimers = timerfindall; | |
481 if strcmp(get(alltimers(1),'Running'),'off'), start(alltimers(1)); end | |
482 end | |
483 %---------------------------------------------------------------------- | |
484 | |
485 %---------------------------------------------------------------------- | |
486 function HelpCallback(varargin) | |
487 % Whenever the user doubleclick a block in the library window (ie, the | |
488 % OpenFcn callback is executed from the library). | |
489 | |
490 openSys = find_system('SearchDepth',0); | |
491 for ii=1:numel(openSys) | |
492 if ~isempty(find_system(openSys{ii},'FindAll','on','Type','Annotation','Tag','ltpda model')) | |
493 add_block(gcb,[openSys{ii},'/',get_param(gcb,'Name')],'MakeNameUnique','on') | |
494 return; | |
495 end | |
496 end | |
497 try | |
498 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function'); | |
499 functionname = get_param(childpath,'Tag'); | |
500 | |
501 description = get_param(gcbh,'Description'); | |
502 funcname = findstr('functionName=',description); | |
503 if funcname | |
504 i = funcname+14; | |
505 while ~strcmp(description(i),';'), i=i+1; end | |
506 functionname = description(funcname+14:i-2); | |
507 end | |
508 | |
509 [func,classes] = strtok(get(gcbh,'Tag')); | |
510 if strcmp(func,'method') | |
511 helptext = help([strtrim(classes),'/',functionname]); | |
512 else | |
513 helptext = help(functionname); | |
514 end | |
515 | |
516 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')); | |
517 % Help text: | |
518 uicontrol('Parent',helpFigure,'Units','normalized','HorizontalAlignment','left','Position',[0 0 1 1],'FontSize',8,'String',helptext,'Visible','on','max',100,'Style','edit'); | |
519 catch | |
520 end | |
521 end | |
522 %---------------------------------------------------------------------- | |
523 | |
524 end |