Mercurial > hg > ltpda
comparison m-toolbox/m/gui/gltpda/pan7partial.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 pan7partial(varargin) | |
2 | |
3 % ======================================================================== | |
4 % ===================== Panel for partial execution ====================== | |
5 % ======================================================================== | |
6 % | |
7 % $Id: pan7partial.m,v 1.3 2008/08/30 12:27:08 nicola Exp $ | |
8 | |
9 scaleX = getappdata(0, 'ltpda_gui_scalefactor'); | |
10 guiFontSize = round(8*scaleX); | |
11 | |
12 alltimers = timerfindall; | |
13 stop(alltimers(2)); | |
14 set(alltimers(2),'TimerFcn',@ContinuousCheck,'Period',1); | |
15 start(alltimers(2)); | |
16 | |
17 %% | |
18 | |
19 currPanel = varargin{1}; | |
20 panelDimens = get(currPanel, 'Position'); | |
21 backColor = get(currPanel, 'BackgroundColor'); | |
22 | |
23 % Current system: | |
24 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Units','normalized','Position',[0.17 0.89 0.125 0.040],'String','Current system:','FontName','Times New Roman','FontSize',guiFontSize+4,'FontWeight','normal','Visible','on','Style','text'); | |
25 currsystem = bdroot; | |
26 if isempty(currsystem) || isempty(find_system(currsystem,'FindAll','on','Type','Annotation','Tag','ltpda model')), currsystem = 'None'; end | |
27 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Units','normalized','Position',[0.3 0.89 0.1875 0.040],'String',currsystem,'FontName','Times New Roman','FontSize',guiFontSize+4,'FontWeight','bold','Visible','on','UserData','currsystem','Style','text'); | |
28 | |
29 % Current block: | |
30 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Units','normalized','Position',[0.5 0.89 0.125 0.040],'String','Current block:','FontName','Times New Roman','FontSize',guiFontSize+4,'FontWeight','normal','Visible','on','Style','text'); | |
31 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Units','normalized','Position',[0.62 0.89 0.1875 0.040],'String','','FontName','Times New Roman','FontSize',guiFontSize+4,'FontWeight','bold','Visible','on','UserData','currblock','Style','text'); | |
32 | |
33 | |
34 % ======================================================================= | |
35 FirstPanPos = [.0125 .56 .975 .26]; | |
36 hFirstPanel = uipanel('Parent',currPanel,'BackgroundColor',backColor,'FontSize',guiFontSize-1,'Units','normalized','Position',FirstPanPos); | |
37 logosize = [53 55]*scaleX; | |
38 icon1 = axes('Parent',hFirstPanel,'Units','normalized','Position',[.03 .45 0.3 0.3]); | |
39 iconSize = getpixelposition(icon1); panelSize = getpixelposition(hFirstPanel); iconSize(3:4) = logosize; iconSize(2)= (panelSize(4)-iconSize(4))/2; setpixelposition(icon1,iconSize); | |
40 image(imread('iconpar1.jpg'),'Parent',icon1,'Tag','partial1'); | |
41 axis(icon1,'off'); | |
42 clear logosize iconSize panelSize | |
43 | |
44 firstText = sprintf('Execution from the beginning to the current block.\n\nThis option is always possible: are executed only those blocks parent of the current one, and the execution is stopped as soon as the current one is reached.'); | |
45 uicontrol('Parent',hFirstPanel,'BackgroundColor',backColor,'Units','normalized','HorizontalAlignment','left','Position',[0.15 0.2 0.8 0.6],'String',firstText,'FontSize',guiFontSize,'Visible','on','Style','text','Tag','infotext1'); | |
46 | |
47 % ======================================================================= | |
48 SecondPanPos = [.0125 .29 .975 .26]; | |
49 hSecondPanel = uipanel('Parent',currPanel,'BackgroundColor',backColor,'FontSize',guiFontSize-1,'Units','normalized','Position',SecondPanPos); | |
50 logosize = [53 55]*scaleX; | |
51 icon2 = axes('Parent',hSecondPanel,'Units','normalized','Position',[.03 .45 0.3 0.3]); | |
52 iconSize = getpixelposition(icon2); panelSize = getpixelposition(hFirstPanel); iconSize(3:4) = logosize; iconSize(2)= (panelSize(4)-iconSize(4))/2; setpixelposition(icon2,iconSize); | |
53 image(imread('iconpar2.jpg'),'Parent',icon2,'Tag','partial2'); | |
54 axis(icon2,'off'); | |
55 clear logosize iconSize panelSize | |
56 | |
57 secondText = sprintf('Execution of the current block only.\n\nThis option is possible only if all the inputs necessary to the currently selected block are available; this means that the model must have already been executed and either all intermediate results are maintained, or just those necessary to the current block.'); | |
58 uicontrol('Parent',hSecondPanel,'BackgroundColor',backColor,'Units','normalized','HorizontalAlignment','left','Position',[0.15 0.2 0.8 0.6],'String',secondText,'FontSize',guiFontSize,'Visible','on','Style','text','Tag','infotext2'); | |
59 | |
60 % ======================================================================= | |
61 ThirdPanPos = [.0125 .02 .975 .26]; | |
62 hThirdPanel = uipanel('Parent',currPanel,'BackgroundColor',backColor,'FontSize',guiFontSize-1,'Units','normalized','Position',ThirdPanPos); | |
63 logosize = [53 55]*scaleX; | |
64 icon3 = axes('Parent',hThirdPanel,'Units','normalized','Position',[.03 .45 0.3 0.3]); | |
65 iconSize = getpixelposition(icon3); panelSize = getpixelposition(hFirstPanel); iconSize(3:4) = logosize; iconSize(2)= (panelSize(4)-iconSize(4))/2; setpixelposition(icon3,iconSize); | |
66 image(imread('iconpar3.jpg'),'Parent',icon3,'Tag','partial3'); | |
67 axis(icon3,'off'); | |
68 clear logosize iconSize panelSize | |
69 | |
70 thirdText = sprintf('Execution from the current block to the end.\n\nThis option is possible only if all the inputs necessary to the currently selected block are available; this means that the model must have already been executed and either all intermediate results are maintained, or just those necessary to the current block.\nAfter the current block the execution continues, updating all the following blocks'); | |
71 uicontrol('Parent',hThirdPanel,'BackgroundColor',backColor,'Units','normalized','HorizontalAlignment','left','Position',[0.15 0.2 0.8 0.6],'String',thirdText,'FontSize',guiFontSize,'Visible','on','Style','text','Tag','infotext3'); | |
72 | |
73 | |
74 UpdatePanel(1); | |
75 | |
76 | |
77 | |
78 %% | |
79 %---------------------------------------------------------------------- | |
80 function ContinuousCheck(varargin) | |
81 % This is the function to execute a continuous timer check | |
82 | |
83 % Keep alive the first timer: | |
84 alltimers = timerfindall; | |
85 if strcmp(get(alltimers(1),'Running'),'off') | |
86 start(alltimers(1)) | |
87 end | |
88 | |
89 currsys = bdroot; | |
90 oldsys = get(findobj('UserData', 'currsystem'), 'String'); | |
91 currselection = utils.prog.gcbsh; | |
92 if numel(currselection)>1, UpdatePanel(1); return; end | |
93 if isempty(currsys) || isempty(currselection), UpdatePanel(1); return; end | |
94 currblock = get_param(currselection,'Name'); | |
95 oldblock = get(findobj('UserData', 'currblock'), 'String'); | |
96 if strcmp(currsys,oldsys) && strcmp(currblock,oldblock), return; end | |
97 | |
98 if ~isempty(currsys) && ~isempty(find_system(currsys,'FindAll','on','Type','Annotation','Tag','ltpda model')) | |
99 currchild = find_system(currselection,'LookUnderMasks','all','BlockType','M-S-Function'); | |
100 if isempty(currchild) || ~strcmp(get_param(currchild,'FunctionName'),'ltpdasim') | |
101 % disp('*** The model is valid, but the selected block is not an LTPDA function block.') | |
102 UpdatePanel(2) | |
103 return; | |
104 else | |
105 annotation = find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'); | |
106 execHistory = get_param(annotation,'UserData'); | |
107 if isempty(execHistory) | |
108 % disp('*** The model is valid, but has never been run.') | |
109 UpdatePanel(3) | |
110 return; | |
111 else | |
112 blockIndex = -1; | |
113 for i=1:size(execHistory,1), if execHistory{i,2}==currselection, blockIndex=i; break; end; end | |
114 if blockIndex==-1 % the current block is not included in the execution history | |
115 % disp('*** The model is valid, but the selected block is not included in the execution history.') | |
116 UpdatePanel(3) | |
117 return; | |
118 end | |
119 for i=3:size(execHistory,2) | |
120 if execHistory{blockIndex,i}==-1 % one of the necessary input has been deleted | |
121 % disp('*** The model and the selected block are valid, but at least one necessary input has been deleted.') | |
122 UpdatePanel(3) | |
123 return; | |
124 end | |
125 end | |
126 % disp('*** The model and the selected block are valid, all necessary inputs available.') | |
127 UpdatePanel(4) | |
128 end | |
129 end | |
130 else | |
131 % disp('*** The model is not valid.') | |
132 UpdatePanel(1) | |
133 end | |
134 | |
135 end | |
136 %---------------------------------------------------------------------- | |
137 | |
138 %---------------------------------------------------------------------- | |
139 function UpdatePanel(varargin) | |
140 % varargin{1}= 1 if all disabled (not a valid ltpda model or ltpda | |
141 % block) | |
142 % 2 if the model is valid but the block is not. | |
143 % 3 if the model and the block are valid, but the block | |
144 % lacks the necessary inputs. | |
145 % 4 model and block valid, all necessary inputs present. | |
146 | |
147 switch varargin{1} | |
148 case 1 | |
149 set(findobj('UserData', 'currsystem'), 'String', 'None') | |
150 set(findobj('UserData', 'currblock'), 'String', '---') | |
151 set(findobj('Tag','partial1'),'CData',imread('iconpar4.jpg'),'ButtonDownFcn',''); | |
152 set(findobj('Tag','partial2'),'CData',imread('iconpar4.jpg'),'ButtonDownFcn',''); | |
153 set(findobj('Tag','partial3'),'CData',imread('iconpar4.jpg'),'ButtonDownFcn',''); | |
154 set(findobj('Tag','infotext1'),'ForegroundColor',[.8 .8 .8]); | |
155 set(findobj('Tag','infotext2'),'ForegroundColor',[.8 .8 .8]); | |
156 set(findobj('Tag','infotext3'),'ForegroundColor',[.8 .8 .8]); | |
157 case 2 | |
158 set(findobj('UserData', 'currsystem'), 'String', bdroot) | |
159 set(findobj('UserData', 'currblock'), 'String', 'Not valid') | |
160 set(findobj('Tag','partial1'),'CData',imread('iconpar4.jpg'),'ButtonDownFcn',''); | |
161 set(findobj('Tag','partial2'),'CData',imread('iconpar4.jpg'),'ButtonDownFcn',''); | |
162 set(findobj('Tag','partial3'),'CData',imread('iconpar4.jpg'),'ButtonDownFcn',''); | |
163 set(findobj('Tag','infotext1'),'ForegroundColor',[.8 .8 .8]); | |
164 set(findobj('Tag','infotext2'),'ForegroundColor',[.8 .8 .8]); | |
165 set(findobj('Tag','infotext3'),'ForegroundColor',[.8 .8 .8]); | |
166 case 3 | |
167 set(findobj('UserData', 'currsystem'), 'String', bdroot) | |
168 set(findobj('UserData', 'currblock'), 'String', get_param(gcbh,'Name')) | |
169 set(findobj('Tag','partial1'),'CData',imread('iconpar1.jpg'),'ButtonDownFcn',@Run1); | |
170 set(findobj('Tag','partial2'),'CData',imread('iconpar4.jpg'),'ButtonDownFcn',''); | |
171 set(findobj('Tag','partial3'),'CData',imread('iconpar4.jpg'),'ButtonDownFcn',''); | |
172 set(findobj('Tag','infotext1'),'ForegroundColor',[0 0 0]); | |
173 set(findobj('Tag','infotext2'),'ForegroundColor',[.8 .8 .8]); | |
174 set(findobj('Tag','infotext3'),'ForegroundColor',[.8 .8 .8]); | |
175 case 4 | |
176 set(findobj('UserData', 'currsystem'), 'String', bdroot) | |
177 set(findobj('UserData', 'currblock'), 'String', get_param(gcbh,'Name')) | |
178 set(findobj('Tag','partial1'),'CData',imread('iconpar1.jpg'),'ButtonDownFcn',@Run1); | |
179 set(findobj('Tag','partial2'),'CData',imread('iconpar2.jpg'),'ButtonDownFcn',@Run2); | |
180 set(findobj('Tag','partial3'),'CData',imread('iconpar3.jpg'),'ButtonDownFcn',@Run3); | |
181 set(findobj('Tag','infotext1'),'ForegroundColor',[0 0 0]); | |
182 set(findobj('Tag','infotext2'),'ForegroundColor',[0 0 0]); | |
183 set(findobj('Tag','infotext3'),'ForegroundColor',[0 0 0]); | |
184 end | |
185 | |
186 end | |
187 %---------------------------------------------------------------------- | |
188 | |
189 %---------------------------------------------------------------------- | |
190 function Run1(varargin) | |
191 % Execution from the beginning to the current block | |
192 | |
193 % To find all parents, up to the beginning of the model: | |
194 parentsBlock = unique(utils.prog.findparent(gcbh)); | |
195 parentsBlock = [parentsBlock ; find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');]; | |
196 | |
197 assignin('base','executionList',parentsBlock); | |
198 ltpdagui('redraw',1.1); | |
199 | |
200 end | |
201 %---------------------------------------------------------------------- | |
202 | |
203 %---------------------------------------------------------------------- | |
204 function Run2(varargin) | |
205 % Execution of the current block only | |
206 | |
207 assignin('base','executionList',find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function') ); | |
208 ltpdagui('redraw',1.1); | |
209 | |
210 end | |
211 %---------------------------------------------------------------------- | |
212 | |
213 %---------------------------------------------------------------------- | |
214 function Run3(varargin) | |
215 % Execution from the current block to the end | |
216 | |
217 % To find all children, up to the end of the model: | |
218 childrenBlock = unique(utils.prog.findchildren(gcbh)); | |
219 childrenBlock(:,2) = 0; | |
220 while min(childrenBlock(:,2))==0 | |
221 for i=1:size(childrenBlock,1) | |
222 if childrenBlock(i,2)==0 | |
223 nextGenerationChildren = utils.prog.findchildren(childrenBlock(i,1)); | |
224 nextGenerationChildren(:,2) = 0; | |
225 if nextGenerationChildren(1,1)~=0 | |
226 childrenBlock = [childrenBlock ; nextGenerationChildren]; | |
227 end | |
228 childrenBlock(i,2) = 1; | |
229 end | |
230 end | |
231 childrenBlock = unique(childrenBlock,'rows'); | |
232 end | |
233 childrenBlock(:,2)=[]; | |
234 childrenBlock = [gcbh ; childrenBlock]; | |
235 | |
236 assignin('base','executionList',childrenBlock); | |
237 ltpdagui('redraw',1.1); | |
238 | |
239 end | |
240 %---------------------------------------------------------------------- | |
241 | |
242 end |