comparison m-toolbox/m/gui/gltpda/pan8nested.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 pan8nested(varargin)
2
3 % ========================================================================
4 % =================== Panel to organize nested loops =====================
5 % ========================================================================
6 %
7 % $Id: pan8nested.m,v 1.3 2008/11/07 17:59:42 nicola Exp $
8
9 scaleX = getappdata(0, 'ltpda_gui_scalefactor');
10 guiFontSize = round(10*scaleX);
11 currPanel = varargin{1};
12 panelDimens = get(currPanel, 'Position');
13 backColor = get(currPanel, 'BackgroundColor');
14
15 global paramLoop currSys enabledNestedParams
16 currSys = '';
17
18 alltimers = timerfindall;
19 stop(alltimers(2));
20 set(alltimers(2),'TimerFcn',@ContinuousCheck,'Period',1);
21 start(alltimers(2));
22
23 %%
24 %----------------------------------------------------------------------
25 function buildNestedPanel(varargin)
26 %----------------------------------------------------------------------
27
28 delete(findobj(gcf,'Parent',currPanel))
29
30 % Check if nested loops execution is enabled or not:
31 nestBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','nestedloops');
32 if isempty(nestBlock)
33 nestedStatus = 0;
34 nestBlock = {''};
35 elseif isempty(get_param(nestBlock{1},'Description'))
36 set_param(nestBlock{1},'Description','0');
37 nestedStatus = 0;
38 else
39 nestedStatus = str2double(get_param(nestBlock{1},'Description'));
40 end
41
42
43 % Enable nested loops:
44 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'TooltipString','Enable or disable the execution of nested loops: when disabled the variables won''t be cleared','Units','normalized','Position',[0.2 0.92 0.2 0.040],'String',' Enable nested loops','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Value',nestedStatus,'Visible','on','Callback',{@enableNested,currPanel,nestBlock{1}},'Style','checkbox');
45
46 % Current system:
47 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Units','normalized','Position',[0.5 0.92 0.125 0.040],'String','Current system:','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Style','text');
48 currsystem = bdroot;
49 if isempty(currsystem) || isempty(find_system(currsystem,'FindAll','on','Type','Annotation','Tag','ltpda model')), currsystem = 'None'; end
50 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Units','normalized','Position',[0.65 0.92 0.25 0.040],'String',currsystem,'FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','UserData','currsystem','Style','text');
51
52 if isempty(nestBlock{1})
53 paramLoop = {};
54 paramnumb = 0;
55 enabledNestedParams = [];
56 else
57 paramLoop = get_param(nestBlock{1},'UserData');
58 paramnumb = size(paramLoop,1);
59 enabledNestedParams = get_param(nestBlock{1},'MaskDescription');
60 if ~isempty(enabledNestedParams)
61 eval(enabledNestedParams);
62 else
63 enabledNestedParams = ones(1,paramnumb);
64 set_param(nestBlock{1},'MaskDescription',['enabledNestedParams = ',mat2str(enabledNestedParams),';'])
65 end
66 end
67
68 for i=1:paramnumb %ie, for every row
69 % Set the proper number to each row:
70 paramLoop{i,1}=i;
71 % Check that every parameter has a valid order value:
72 if isempty(paramLoop{i,2}), paramLoop{i,2}=1; end
73 % Check that every parameter has a name (not empty):
74 if isempty(paramLoop{i,3})
75 ii=1;
76 while ~isempty(findstr(['loop.var',num2str(ii)],[paramLoop{:,3}])), ii=ii+1; end
77 paramLoop{i,3}=['loop.var',num2str(ii)];
78 end
79 % Check that every parameter has a values array (even empty):
80 if isempty(paramLoop{i,6}), paramLoop{i,6}={}; end
81 end
82
83 % % % % Defining the array with the names/handles of all the elements in the GUI:
84 % % % global AllNames
85
86 % Dimensions of all the objects which can be created inside the Loop Panel:
87 AddButtDimension = [20 20]; RemButtDimension = [20 20];
88 LeftArrDimension = [20 20]; RightArrDimension = [20 20];
89 UpArrDimension = [20 15]; DownArrDimension = [20 15];
90 Param2ChangeDimension = [150 20]; IterValDimension = [60 20];
91
92 % Legend (static part of the window):
93 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-80 50 30],'String',{'Add /','Remove'},'FontName','Times New Roman','FontSize',guiFontSize,'Visible','on','Style','text');
94 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[110 panelDimens(4)-85 45 30],'String','Position','FontName','Times New Roman','FontSize',guiFontSize,'Visible','on','Style','text');
95 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[195 panelDimens(4)-85 110 30],'String','Parameter name','FontName','Times New Roman','FontSize',guiFontSize,'Visible','on','Style','text');
96 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[360 panelDimens(4)-85 70 30],'String','Iterations','FontName','Times New Roman','FontSize',guiFontSize,'Visible','on','Style','text');
97
98 % =========================================================================
99 % This part build the dynamic part of the window:
100 % =========================================================================
101 if 40*(paramnumb+3)+20 < panelDimens(4), possible2add = 'on';
102 else possible2add = 'off';
103 end
104
105 for i=1:paramnumb
106 AddButtPosition = [45 panelDimens(4)-40*(i+2)];
107 RemButtPosition = [67 panelDimens(4)-40*(i+2)];
108 LeftArrPosition = [105+30*(paramLoop{i,2}-1) panelDimens(4)-40*(i+2)];
109 UpArrPosition = [125+30*(paramLoop{i,2}-1) panelDimens(4)+8-40*(i+2)];
110 DownArrPosition = [125+30*(paramLoop{i,2}-1) panelDimens(4)-8-40*(i+2)];
111 RightArrPosition = [145+30*(paramLoop{i,2}-1) panelDimens(4)-40*(i+2)];
112 Param2ChangePosition = [180+30*(paramLoop{i,2}-1) panelDimens(4)-40*(i+2)];
113 IterValPosition = [355+30*(paramLoop{i,2}-1) panelDimens(4)-40*(i+2)];
114
115 % Checkbox to enable this param:
116 uicontrol('Parent',currPanel,'Value',enabledNestedParams(i),'TooltipString','Enable or disable this parameter only','Units','pixels','BackGroundColor',[1 1 1],'Position',[15 panelDimens(4)-40*(i+2)+2 15 15],'Visible','on','Enable',possible2add,'UserData',i,'Callback',{@EnableNestedParam,currPanel,nestBlock{1}},'Style','checkbox');
117
118 uicontrol('Parent',currPanel,'TooltipString','Add another parameter','Units','pixels','Position',[AddButtPosition,AddButtDimension],'String','+','Visible','on','Enable',possible2add,'UserData',i,'Callback', @AddButtCallback,'Style','pushbutton');
119 uicontrol('Parent',currPanel,'TooltipString','Remove this parameter','Units','pixels','Position',[RemButtPosition,RemButtDimension],'String','-','Visible','on','Enable','on','UserData',i,'Callback', @RemButtCallback,'Style','pushbutton');
120 LeftArrNames{i} = uicontrol('Parent',currPanel,'TooltipString','Move this parameter to the left','Units','pixels','Position',[LeftArrPosition,LeftArrDimension],'String','<','Visible','on','Enable','on','UserData',i,'Callback', @LeftArrCallback,'Style','pushbutton');
121 RightArrNames{i} = uicontrol('Parent',currPanel,'TooltipString','Move this parameter to the right','Units','pixels','Position',[RightArrPosition,RightArrDimension],'String','>','Visible','on','Enable','on','UserData',i,'Callback', @RightArrCallback,'Style','pushbutton');
122 UpArrNames{i} = uicontrol('Parent',currPanel,'TooltipString','Move this parameter up','Units','pixels','Position',[UpArrPosition,DownArrDimension],'String','','Visible','on','Enable','on','UserData',i,'Callback', @UpArrCallback,'Style','pushbutton');
123 DownArrNames{i} = uicontrol('Parent',currPanel,'TooltipString','Move this parameter down','Units','pixels','Position',[DownArrPosition,UpArrDimension],'String','','Visible','on','Enable','on','UserData',i,'Callback', @DownArrCallback,'Style','pushbutton');
124 uicontrol('Parent',currPanel,'Units','pixels','Position',[Param2ChangePosition,Param2ChangeDimension],'String',paramLoop{i,3},'Visible','on','Enable','on','UserData',i,'Callback',@ParamNameChange,'Style','edit');
125 IterValNames{i} = uicontrol('Parent',currPanel,'TooltipString','The number of iterations associated to this parameter','Units','pixels','Position',[IterValPosition,IterValDimension],'String','-','Visible','on','Enable','on','UserData',i,'Callback',@SetIterations,'Tag',['iterButton',num2str(i)],'Style','pushbutton');
126 if ~isempty(paramLoop{i,4}), set(IterValNames{i},'String',num2str(paramLoop{i,4})); end
127
128 if i==1, set(UpArrNames{i},'Enable','off'); end
129 if i==paramnumb, set(DownArrNames{i},'Enable','off'); end
130
131 if paramLoop{i,2}==paramLoop{i,1}, set(RightArrNames{i},'Enable','off');
132 else set(RightArrNames{i},'Enable','on');
133 end
134
135 if paramLoop{i,2}==1, set(LeftArrNames{i},'Enable','off');
136 else set(LeftArrNames{i},'Enable','on');
137 end
138
139 end
140
141 % Last button to add a parameter:
142 paramnumb = paramnumb+1;
143 uicontrol('Parent',currPanel,'Units','pixels','Position',[45 panelDimens(4)-40*(paramnumb+2) 20 20],'String','+','Visible','on','Enable',possible2add,'UserData',paramnumb,'Callback', @AddButtCallback,'Tag','lastaddbutton','Style','pushbutton');
144
145 if ~nestedStatus
146 set([findobj(currPanel,'Style','pushbutton');findobj(currPanel,'Style','edit')],'Enable','off');
147 set(findobj(currPanel,'Style','text'),'ForegroundColor',[.8 .8 .8]);
148 set(findobj(currPanel,'Tag','lastaddbutton'),'enable','on')
149 end
150
151 end
152
153
154 %%
155
156 % ======================================================================
157 % ======================================================================
158 % ============================= FUNCTIONS ==============================
159 % ======================================================================
160 % ======================================================================
161
162 %%
163 %----------------------------------------------------------------------
164 function ContinuousCheck(varargin)
165 % This is the function to execute a continuous check on the status
166 % of the current selection, to verify that a valid LTPDA model is
167 % selected.
168
169 % Clear if nothing's selected
170 if isempty(bdroot) || strcmp(get_param(bdroot,'BlockDiagramType'),'library') || isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
171 delete(findobj(gcf,'Parent',currPanel))
172 currSys = '';
173 paramLoop = [];
174 enabledNestedParams = [];
175 return
176 else
177 if ~strcmp(gcs,currSys)
178 % The selection changed: redraw the panel.
179 currSys = gcs;
180 enabledNestedParams = [];
181 buildNestedPanel();
182 end
183 end
184
185 end
186 %----------------------------------------------------------------------
187
188 %----------------------------------------------------------------------
189 function enableNested(hObject, varargin)
190 % Callback for the 'Enable nested loops' checkbox.
191
192 currStatus = get(hObject,'Value');
193 currPanel = varargin{2};
194 nestBlock = varargin{3};
195 allElements = [findobj(currPanel,'Style','pushbutton');findobj(currPanel,'Style','edit');findobj(currPanel,'Style','checkbox')];
196 allTexts = findobj(currPanel,'Style','text');
197
198 if isempty(nestBlock)
199 paramLoop = {1,1,[],[],[],{},[]};
200 nestBlock = add_block('ltpda_library/Commonly Used Blocks/Globals',[bdroot '/Nested loops']);
201 annotation = find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model');
202 position = get_param(annotation,'Position');
203 set_param(nestBlock,'LinkStatus','inactive','Showname','off','MaskDisplay','disp(''Nested loops'')','Tag','nestedloops','DropShadow','on','Position',[position(1)+20 position(2)-42 position(1)+150 position(2)-27 ])
204 set_param(nestBlock,'UserData',paramLoop,'UserDataPersistent','on')
205 end
206
207 switch currStatus
208 case 1
209 set_param(nestBlock,'Description','1');
210 set_param(nestBlock,'UserData',paramLoop);
211 buildNestedPanel();
212 case 0
213 set_param(nestBlock,'Description','0');
214 set(allElements,'Enable','off');
215 set(hObject,'Enable','on')
216 set(findobj(currPanel,'Tag','lastaddbutton'),'enable','on')
217 set(allTexts,'ForegroundColor',[.8 .8 .8]);
218 end
219
220 end
221 %----------------------------------------------------------------------
222
223 %----------------------------------------------------------------------
224 function EnableNestedParam(hObject, varargin)
225 % Callback for the 'Enable nested param' checkbox, for EVERY PARAM.
226
227 currStatus = get(hObject,'Value');
228 currPanel = varargin{2};
229 nestBlock = varargin{3};
230 currParamIndex = get(hObject,'UserData');
231
232 enabledNestedParams(currParamIndex) = currStatus;
233 set_param(nestBlock,'MaskDescription',['enabledNestedParams = ',mat2str(enabledNestedParams),';'])
234
235 end
236 %----------------------------------------------------------------------
237
238 %----------------------------------------------------------------------
239 function AddButtCallback(hObject, varargin)
240 % Callback function: run when the user click on the Add button: another
241 % parameter is added BELOW the row where user has clicked.
242
243 % Retrieve the index (row) of the clicked button:
244 currParamIndex = get(hObject,'UserData');
245 if currParamIndex==1 && isempty(paramLoop)
246 paramLoop = {1,1,[],[],[],{},[]};
247 nestBlock = add_block('ltpda_library/Commonly Used Blocks/Globals',[bdroot '/Nested loops']);
248 annotation = find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model');
249 position = get_param(annotation,'Position');
250 set_param(nestBlock,'LinkStatus','inactive','Showname','off','MaskDisplay','disp(''Nested loops'')','Tag','nestedloops','DropShadow','on','Position',[position(1)+20 position(2)-42 position(1)+150 position(2)-27 ])
251 set_param(nestBlock,'Description','1','UserData',paramLoop,'UserDataPersistent','on')
252 enabledNestedParams = 1;
253 set_param(nestBlock,'MaskDescription','enabledNestedParams = 1;')
254
255 else
256 if currParamIndex > size(paramLoop,1), currParamIndex = size(paramLoop,1); end
257 paramLoop = [paramLoop(1:currParamIndex,:);cell(1,7);paramLoop(currParamIndex+1:end,:)];
258 currParamIndex = currParamIndex+1;
259 paramLoop{currParamIndex,1} = currParamIndex;
260 paramLoop{currParamIndex,2} = paramLoop{currParamIndex-1,2};
261 nestBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','nestedloops');
262 set_param(nestBlock{1},'Description','1','UserData',paramLoop);
263 enabledNestedParams = [enabledNestedParams , 1];
264 set_param(nestBlock{1},'MaskDescription',['enabledNestedParams = ',mat2str(enabledNestedParams),';'])
265 end
266
267
268 buildNestedPanel()
269
270 end
271 %----------------------------------------------------------------------
272
273 %----------------------------------------------------------------------
274 function RemButtCallback(hObject, varargin)
275 % Callback function: run when the user click on the Remove button
276
277 % Retrieve the index of the clicked button:
278 currParamIndex = get(hObject,'UserData');
279 nestBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','nestedloops');
280
281 if currParamIndex==1 && size(paramLoop,1)==1
282 clear paramLoop enabledNestedParams
283 delete_block(nestBlock{1})
284 else
285 xx = size(paramLoop,1);
286 ii = currParamIndex+1;
287 while ii <= xx && paramLoop{ii,2} > paramLoop{currParamIndex,2}
288 paramLoop{ii,2} = paramLoop{ii,2}-1;
289 ii = ii+1;
290 end
291 paramLoop = [paramLoop(1:currParamIndex-1,:);paramLoop(currParamIndex+1:end,:)];
292 set_param(nestBlock{1},'UserData',paramLoop);
293 enabledNestedParams(currParamIndex) = [];
294 set_param(nestBlock{1},'MaskDescription',['enabledNestedParams = ',mat2str(enabledNestedParams),';'])
295 end
296
297 buildNestedPanel()
298
299 end
300 %----------------------------------------------------------------------
301
302 %----------------------------------------------------------------------
303 function LeftArrCallback(hObject, varargin)
304 % Callback function: run when the user click on the Left Arrow button
305
306 % Retrieve the number of the modified parameter:
307 currParamIndex = get(hObject,'UserData');
308
309 xx = size(paramLoop,1);
310 ii = currParamIndex+1;
311 while ii <= xx && paramLoop{ii,2} > paramLoop{currParamIndex,2}
312 paramLoop{ii,2} = paramLoop{ii,2}-1;
313 ii = ii+1;
314 end
315 paramLoop{currParamIndex,2} = paramLoop{currParamIndex,2}-1;
316
317 nestBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','nestedloops');
318 set_param(nestBlock{1},'UserData',paramLoop);
319 buildNestedPanel()
320
321 end
322 %----------------------------------------------------------------------
323
324 %----------------------------------------------------------------------
325 function RightArrCallback(hObject, varargin)
326 % Callback function: run when the user click on the Right Arrow button
327
328 % Retrieve the number of the modified parameter:
329 currParamIndex = get(hObject,'UserData');
330
331 % Move to the right the parents parameters:
332 ii=currParamIndex;
333 if ii>1 && paramLoop{currParamIndex,2}<paramLoop{currParamIndex,1}
334 while paramLoop{ii-1,2}==paramLoop{ii,2}-1
335 % ie, till when the previous parameters are parents:
336 ii=ii-1;
337 if ii==2, break; end
338 end
339 % ii is the first parent parameter
340 if paramLoop{currParamIndex,2}<=paramLoop{currParamIndex,1}
341 for i=ii:currParamIndex, paramLoop{i,2}=paramLoop{i,2}+1; end
342 end
343 end
344
345 nestBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','nestedloops');
346 set_param(nestBlock{1},'UserData',paramLoop);
347 buildNestedPanel()
348
349 end
350 %----------------------------------------------------------------------
351
352 %----------------------------------------------------------------------
353 function UpArrCallback(hObject, varargin)
354 % Callback function: run when the user click on the Up Arrow button
355
356 % Retrieve the number of the modified parameter:
357 currParamIndex = get(hObject,'UserData');
358 xx = size(paramLoop,1);
359
360 % Move to the left the parameters children:
361 ii=currParamIndex;
362 if ii<xx
363 while paramLoop{ii+1,2}==paramLoop{ii,2}+1
364 % ie, till when the next parameters are children:
365 ii=ii+1;
366 if ii==xx, break; end
367 end
368 end
369 % ii is the last children parameter
370 for i=currParamIndex+1:ii, paramLoop{i,2}=paramLoop{i,2}-1; end
371
372 % We move up the selected row:
373 paramLoop([currParamIndex-1,currParamIndex],:) = paramLoop([currParamIndex,currParamIndex-1],:);
374 paramLoop{currParamIndex-1,2} = paramLoop{currParamIndex,2};
375 enabledNestedParams([currParamIndex-1,currParamIndex]) = enabledNestedParams([currParamIndex,currParamIndex-1]);
376
377 for i=1:xx, paramLoop{i,1}=i; end
378 nestBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','nestedloops');
379 set_param(nestBlock{1},'UserData',paramLoop);
380 set_param(nestBlock{1},'MaskDescription',['enabledNestedParams = ',mat2str(enabledNestedParams),';'])
381 buildNestedPanel()
382
383 end
384 %----------------------------------------------------------------------
385
386 %----------------------------------------------------------------------
387 function DownArrCallback(hObject, varargin)
388 % Callback function: run when the user click on the Down Arrow button
389
390 % Retrieve the number of the modified parameter:
391 currParamIndex = get(hObject,'UserData');
392 xx = size(paramLoop,1);
393
394 % Move to the left the parameters children:
395 ii=currParamIndex;
396 if ii<xx
397 while paramLoop{ii+1,2}==paramLoop{ii,2}+1
398 % ie, till when the next parameters are children:
399 ii=ii+1;
400 if ii==xx, break; end
401 end
402 end
403 for i=currParamIndex+1:ii, paramLoop{i,2}=paramLoop{i,2}-1; end
404
405 % We move down the selected row:
406 paramLoop([currParamIndex,currParamIndex+1],:) = paramLoop([currParamIndex+1,currParamIndex],:);
407 paramLoop{currParamIndex,2}=paramLoop{currParamIndex+1,2};
408 enabledNestedParams([currParamIndex,currParamIndex+1]) = enabledNestedParams([currParamIndex+1,currParamIndex]);
409
410 for i=1:xx, paramLoop{i,1}=i; end
411 nestBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','nestedloops');
412 set_param(nestBlock{1},'UserData',paramLoop);
413 set_param(nestBlock{1},'MaskDescription',['enabledNestedParams = ',mat2str(enabledNestedParams),';'])
414 buildNestedPanel()
415
416 end
417 %----------------------------------------------------------------------
418
419 %----------------------------------------------------------------------
420 function ParamNameChange(hObject, varargin)
421 % Callback function: run when the user changes the name of the variable
422
423 % Retrieve the number of the modified parameter:
424 currParamIndex = get(hObject,'UserData');
425
426 newName = get(hObject,'String');
427 oldName = paramLoop{currParamIndex,3};
428
429 if isempty(newName) || ismember(newName,paramLoop(:,3)), set(hObject,'String',oldName), return; end
430 if numel(newName)<6 || ~strcmp(newName(1:5),'loop.'), newName = ['loop.',strrep(newName,'.','')]; set(hObject,'String',newName); end
431
432 paramLoop{currParamIndex,3} = newName;
433 nestBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','nestedloops');
434 set_param(nestBlock{1},'UserData',paramLoop);
435
436 end
437 %----------------------------------------------------------------------
438
439 %%
440 %----------------------------------------------------------------------
441 function SetIterations(hObject,varargin)
442
443 existingFig = findobj('Name','Set iterations');
444 if ~isempty(existingFig), close(existingFig); end
445
446 % Retrieve the number of the modified parameter:
447 currParamIndex = get(hObject,'UserData');
448 if ~isempty(paramLoop{currParamIndex,5}) % then there are range settings
449 range = paramLoop{currParamIndex,5};
450 min = num2str(range(1)); step = num2str(range(2)); max = num2str(range(3));
451 range = 1;
452 else % there are just direct values settings
453 min = ''; step = ''; max = '';
454 range = 0;
455 end
456
457 screenSize = get(0,'ScreenSize');
458 backColor = [1 1 1];
459 setIterSize = [570, 280];
460 position = [(screenSize(3)-setIterSize(1))/2 , (screenSize(4)-setIterSize(2))/2 , setIterSize];
461 setIterFig = figure('Position',position,'Name','Set iterations','Tag','setiterations','Resize','off','NumberTitle','off','Toolbar','none','Menubar','none');
462 % Texts
463 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[30 position(4)-40 80 20],'String','Default:','FontName','Times New Roman','FontSize',guiFontSize+3,'FontWeight','bold','Visible','on','Style','text');
464 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[30 position(4)-80 80 20],'String','Iterations:','FontName','Times New Roman','FontSize',guiFontSize+3,'FontWeight','bold','Visible','on','Style','text');
465 % Radio buttons:
466 rangeORvalues = uibuttongroup('Parent',setIterFig,'BackgroundColor',backColor,'visible','on','SelectionChangeFcn',@enableRangeOrValues);
467 uicontrol('Parent',rangeORvalues,'BackgroundColor',backColor,'UserData',0,'HorizontalAlignment','center','Position',[150 position(4)-80 100 20],'String','Range:','FontName','Times New Roman','FontSize',guiFontSize+1,'Visible','on','Value',range,'Style','radiobutton');
468 uicontrol('Parent',rangeORvalues,'BackgroundColor',backColor,'UserData',1,'HorizontalAlignment','center','Position',[150 position(4)-110 100 20],'String','Values:','FontName','Times New Roman','FontSize',guiFontSize+1,'Visible','on','Value',~range,'Style','radiobutton');
469
470 % Default:
471 defVal = paramLoop{currParamIndex,7};
472 if isempty(defVal), defVal = ''; end
473 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[140 position(4)-40 100 20],'String',defVal,'TooltipString','This value will be used whenever this variable isn''t looping, or nested loops are disabled','Enable','on','Tag','defaultvalue','Style','edit');
474
475 % GUI elements for range settings:
476 inputExamples = {'Insert only';...
477 'scalar';...
478 'numbers:'};
479 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[270 position(4)-250 80 170],'String',inputExamples,'Visible','on','Tag','range','Style','text');
480 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[350 position(4)-85 50 20],'String','Min:','Visible','off','Enable','on','Tag','range','Style','text');
481 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[400 position(4)-80 50 20],'String',min,'Visible','off','Enable','on','Tag','rangemin','Style','edit');
482 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[350 position(4)-115 50 20],'String','Step:','Visible','off','Enable','on','Tag','range','Style','text');
483 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[400 position(4)-110 50 20],'String',step,'Visible','off','Enable','on','Tag','rangestep','Style','edit');
484 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[350 position(4)-145 50 20],'String','Max:','Visible','off','Enable','on','Tag','range','Style','text');
485 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[400 position(4)-140 50 20],'String',max,'Visible','off','Enable','on','Tag','rangemax','Style','edit');
486 % Apply button:
487 uicontrol('Parent',setIterFig,'BackgroundColor',[.9 .9 .9],'Units','pixels','Position',[250 15 60 25],'String','Apply >','Visible','off','Enable','on','Callback',@calcIterRange,'UserData',0,'Tag','range','Style','pushbutton');
488 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[325 17 200 20],'String','---','FontSize',guiFontSize+1,'Visible','off','Tag','rangeIter','Style','text');
489
490 % GUI elements for direct values settings:
491 listInput = paramLoop{currParamIndex,6};
492 inputExamples = {'Examples:';...
493 ' 1';...
494 ' 2';...
495 ' ';...
496 ' or:';...
497 ' ''one''';...
498 ' ''two''';...
499 ' ';...
500 ' or:';...
501 ' [1:5]';...
502 ' [10:10:50]'};
503 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[270 position(4)-230 140 170],'String',inputExamples,'Visible','on','Tag','values','Style','text');
504 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[360 position(4)-210 150 150],'String',listInput,'Max',10,'FontSize',guiFontSize,'Visible','on','Enable','on','Callback',@valuesListCallback,'Tag','valuesList','UserData',currParamIndex,'Style','edit');
505 % Apply button:
506 uicontrol('Parent',setIterFig,'BackgroundColor',[.9 .9 .9],'Units','pixels','Position',[250 15 60 25],'String','Apply >','Visible','on','Enable','on','Callback',@calcIterRange,'UserData',1,'Tag','values','Style','pushbutton');
507 uicontrol('Parent',setIterFig,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[325 17 200 20],'String','---','FontSize',guiFontSize+1,'Visible','on','Tag','valuesIter','Style','text');
508
509 if ~isempty(paramLoop{currParamIndex,6}) % then there are values
510 numbIter = numel(paramLoop{currParamIndex,6});
511 set(findobj(gcf,'tag','valuesIter'),'String',[num2str(numbIter),' iterations'])
512 set(findobj(gcf,'tag','rangeIter'),'String',[num2str(numbIter),' iterations'])
513 end
514
515 if range, enableRangeOrValues(-1,0)
516 else enableRangeOrValues(-1,1)
517 end
518
519 end
520 %----------------------------------------------------------------------
521
522 %----------------------------------------------------------------------
523 function enableRangeOrValues(hObject,varargin)
524
525 if hObject==-1, rangeORvalue = varargin{1};
526 else rangeORvalue = get(get(hObject,'SelectedObject'),'userdata');
527 end
528
529 if rangeORvalue % value
530 set(findobj(gcf,'-regexp','Tag','^range'),'visible','off')
531 set(findobj(gcf,'-regexp','Tag','^values'),'visible','on')
532 else % range
533 set(findobj(gcf,'-regexp','Tag','^range'),'visible','on')
534 set(findobj(gcf,'-regexp','Tag','^values'),'visible','off')
535 end
536
537 end
538 %----------------------------------------------------------------------
539
540 %----------------------------------------------------------------------
541 function calcIterRange(hObject,varargin)
542
543 rangeORvalue = get(hObject,'userdata');
544 defaultVal = findobj(gcf,'Tag','defaultvalue');
545 if isempty(get(defaultVal,'String'))
546 set(findobj(gcf,'tag','valuesIter'),'String','Please insert a default value')
547 return
548 end
549
550 if rangeORvalue % value
551 try
552 listField = findobj(gcf,'tag','valuesList');
553 valuesList = get(listField,'String');
554 currParamIndex = get(listField,'UserData');
555 numbIter = size(valuesList,1);
556 paramLoop{currParamIndex,4} = numbIter;
557 paramLoop{currParamIndex,5} = [];
558 paramLoop{currParamIndex,6} = valuesList;
559 nestBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','nestedloops');
560 set_param(nestBlock{1},'UserData',paramLoop);
561
562 set(findobj(gcf,'tag','rangemin'),'String','')
563 set(findobj(gcf,'tag','rangestep'),'String','')
564 set(findobj(gcf,'tag','rangemax'),'String','')
565 set(findobj(gcf,'tag','valuesIter'),'String',[num2str(numbIter),' iterations'])
566 set(findobj('Tag',['iterButton',num2str(currParamIndex)]),'String',num2str(numbIter))
567 catch
568 set(findobj(gcf,'tag','valuesIter'),'String','Error')
569 end
570 else % range
571 try
572 minVal = str2double(get(findobj(gcf,'tag','rangemin'),'String'));
573 stepVal = str2double(get(findobj(gcf,'tag','rangestep'),'String'));
574 maxVal = str2double(get(findobj(gcf,'tag','rangemax'),'String'));
575 valuesList = num2cell([minVal:stepVal:maxVal]'); %#ok<NBRAK>
576 if ~iscell(valuesList) && isnan(valuesList), error(''); end
577 listField = findobj(gcf,'tag','valuesList');
578 currParamIndex = get(listField,'UserData');
579 numbIter = size(valuesList,1);
580 paramLoop{currParamIndex,4} = numbIter;
581 paramLoop{currParamIndex,5} = [minVal,stepVal,maxVal];
582 paramLoop{currParamIndex,6} = valuesList;
583 nestBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','nestedloops');
584 set_param(nestBlock{1},'UserData',paramLoop);
585
586 set(findobj(gcf,'tag','valuesList'),'String',valuesList)
587 set(findobj(gcf,'tag','rangeIter'),'String',[num2str(numbIter),' iterations'])
588 set(findobj('Tag',['iterButton',num2str(currParamIndex)]),'String',num2str(numbIter))
589 catch
590 set(findobj(gcf,'tag','rangeIter'),'String','Error')
591 end
592 end
593 paramLoop{currParamIndex,7} = get(defaultVal,'String');
594
595 nestBlock = find_system(bdroot,'SearchDepth',1,'BlockType','SubSystem','Tag','nestedloops');
596 set_param(nestBlock{1},'UserData',paramLoop);
597 end
598 %----------------------------------------------------------------------
599
600 %----------------------------------------------------------------------
601 function valuesListCallback(hObject, varargin)
602
603 valuesList = get(hObject,'String');
604 currParamIndex = get(hObject,'UserData');
605 paramLoop{currParamIndex,6} = valuesList;
606
607 end
608 %----------------------------------------------------------------------
609
610 end