comparison m-toolbox/sltpda/sltpda_control.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 varargout = sltpda_control(varargin)
2 % SLTPDA_CONTROL M-file for sltpda_control.fig
3 % SLTPDA_CONTROL, by itself, creates a new SLTPDA_CONTROL or raises the existing
4 % singleton*.
5 %
6 % H = SLTPDA_CONTROL returns the handle to a new SLTPDA_CONTROL or the handle to
7 % the existing singleton*.
8 %
9 % SLTPDA_CONTROL('CALLBACK',hObject,eventData,handles,...) calls the local
10 % function named CALLBACK in SLTPDA_CONTROL.M with the given input arguments.
11 %
12 % SLTPDA_CONTROL('Property','Value',...) creates a new SLTPDA_CONTROL or raises the
13 % existing singleton*. Starting from the left, property value pairs are
14 % applied to the GUI before sltpda_control_OpeningFunction gets called. An
15 % unrecognized property name or invalid value makes property application
16 % stop. All inputs are passed to sltpda_control_OpeningFcn via varargin.
17 %
18 % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
19 % instance to run (singleton)".
20 %
21 % See also: GUIDE, GUIDATA, GUIHANDLES
22
23 % Edit the above text to modify the response to help sltpda_control
24
25 % Last Modified by GUIDE v2.5 04-May-2007 09:13:16
26
27 % Begin initialization code - DO NOT EDIT
28 gui_Singleton = 1;
29 gui_State = struct('gui_Name', mfilename, ...
30 'gui_Singleton', gui_Singleton, ...
31 'gui_OpeningFcn', @sltpda_control_OpeningFcn, ...
32 'gui_OutputFcn', @sltpda_control_OutputFcn, ...
33 'gui_LayoutFcn', [] , ...
34 'gui_Callback', []);
35 if nargin && ischar(varargin{1})
36 gui_State.gui_Callback = str2func(varargin{1});
37 end
38
39 if nargout
40 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41 else
42 gui_mainfcn(gui_State, varargin{:});
43 end
44 % End initialization code - DO NOT EDIT
45
46
47 % --- Executes just before sltpda_control is made visible.
48 function sltpda_control_OpeningFcn(hObject, eventdata, handles, varargin)
49 % This function has no output args, see OutputFcn.
50 % hObject handle to figure
51 % eventdata reserved - to be defined in a future version of MATLAB
52 % handles structure with handles and user data (see GUIDATA)
53 % varargin command line arguments to sltpda_control (see VARARGIN)
54
55 % Choose default command line output for sltpda_control
56 handles.output = hObject;
57
58 % Update handles structure
59 guidata(hObject, handles);
60
61 % UIWAIT makes sltpda_control wait for user response (see UIRESUME)
62 % uiwait(handles.main);
63
64 % load logo and display in axes
65 logo = imread('images/sltpda.jpg');
66 image(logo, 'Parent', handles.logoAxes)
67 set(handles.logoAxes,'Visible', 'off');
68
69
70 % make a timer object which gets the currently selected SIMULINK model
71 csyst = timer();
72 set(csyst, 'TimerFcn', {@setCurrentModel,handles.currentModelTxt});
73 set(csyst, 'Period', 0.5, 'ExecutionMode', 'FixedRate');
74 start(csyst);
75 setappdata(handles.main, 'csyst', csyst);
76
77 % % make a timer object which gets the parameters for the current block
78 % cbt = timer();
79 % set(cbt, 'TimerFcn', {@setCurrentBlock,handles});
80 % set(cbt, 'Period', 0.5, 'ExecutionMode', 'FixedRate');
81 % start(cbt);
82 % setappdata(handles.main, 'cbt', cbt);
83
84 % setup loops
85 loops = [];
86 setappdata(handles.main, 'loops', loops);
87
88
89
90 % --- Outputs from this function are returned to the command line.
91 function varargout = sltpda_control_OutputFcn(hObject, eventdata, handles)
92 % varargout cell array for returning output args (see VARARGOUT);
93 % hObject handle to figure
94 % eventdata reserved - to be defined in a future version of MATLAB
95 % handles structure with handles and user data (see GUIDATA)
96
97 % Get default command line output from handles structure
98 varargout{1} = handles.output;
99
100
101 % --- Executes during object creation, after setting all properties.
102 function main_CreateFcn(hObject, eventdata, handles)
103 % hObject handle to main (see GCBO)
104 % eventdata reserved - to be defined in a future version of MATLAB
105 % handles empty - handles not created until after all CreateFcns called
106
107
108 % --- Executes on button press in openToolboxBtn.
109 function openToolboxBtn_Callback(hObject, eventdata, handles)
110 % hObject handle to openToolboxBtn (see GCBO)
111 % eventdata reserved - to be defined in a future version of MATLAB
112 % handles structure with handles and user data (see GUIDATA)
113
114 open('sltpda.mdl')
115
116
117
118 % --- Executes on button press in openModel.
119 function openModel_Callback(hObject, eventdata, handles)
120 % hObject handle to openModel (see GCBO)
121 % eventdata reserved - to be defined in a future version of MATLAB
122 % handles structure with handles and user data (see GUIDATA)
123
124 % Pop-up dialog box to choose model file
125 [filename, pathname] = uigetfile({'*.mdl', 'sLTPDA Model File';
126 '*.xml', 'LTPDA XML AO File'},...
127 'MDL-file input',...
128 'MultiSelect', 'on');
129
130 if filename ~= 0
131 % Loop over selected files
132 if iscellstr(filename)
133 nfiles = length(filename);
134 for f=1:nfiles
135 [path, name, ext, vers] = fileparts(char(filename(f)));
136 switch ext
137 case '.mdl'
138 infile = fullfile(pathname, char(filename(f)));
139 case '.xml'
140 % make mdl file from ao
141 a = ao(char(filename(f)));
142 mdlfilename = get(a, 'mdlfilename');
143 mdlfilein = get(a, 'mdlfile');
144 idx = strfind(mdlfilein, '\n');
145 % convert mdlfile to a file
146 fd = fopen(mdlfilename, 'w+');
147 for j=1:length(idx)-1
148 i1 = idx(j)+2;
149 i2 = idx(j+1)-1;
150 fprintf(fd, '%s\n', mdlfilein(i1:i2));
151 end
152 fprintf(fd, '}\n');
153 fclose(fd);
154
155 infile = mdlfilename;
156 otherwise
157 error('### unknown file type.');
158 end
159 open_system(infile);
160 end
161 else
162 [path, name, ext, vers] = fileparts(char(filename));
163 switch ext
164 case '.mdl'
165 infile = fullfile(pathname, char(filename));
166 case '.xml'
167 % make mdl file from ao
168 a = ao(char(filename));
169 mdlfilename = get(a, 'mdlfilename');
170 mdlfilein = get(a, 'mdlfile');
171 idx = strfind(mdlfilein, '\n');
172 % convert mdlfile to a file
173 fd = fopen(mdlfilename, 'w+');
174 for j=1:length(idx)-1
175 i1 = idx(j)+2;
176 i2 = idx(j+1)-1;
177 fprintf(fd, '%s\n', mdlfilein(i1:i2));
178 end
179 fprintf(fd, '}\n');
180 fclose(fd);
181
182 infile = mdlfilename;
183 otherwise
184 error('### unknown file type.');
185 end
186 open_system(infile);
187 end
188 end
189
190 % --- Executes on button press in runModel.
191 function runModel_Callback(hObject, eventdata, handles)
192 % hObject handle to runModel (see GCBO)
193 % eventdata reserved - to be defined in a future version of MATLAB
194 % handles structure with handles and user data (see GUIDATA)
195
196 % get current model name
197 model = get(handles.currentModelTxt, 'String');
198 sltpda_execute_loops(model);
199
200 % --- Executes during object creation, after setting all properties.
201 function currentModelTxt_CreateFcn(hObject, eventdata, handles)
202 % hObject handle to currentModelTxt (see GCBO)
203 % eventdata reserved - to be defined in a future version of MATLAB
204 % handles empty - handles not created until after all CreateFcns called
205
206 %--------------------------------------------------------------------------
207 %
208 function setCurrentModel(obj, event, handles)
209
210 try
211 set(handles, 'String', gcs);
212 catch
213 set(handles, 'String', '');
214 end
215
216
217 % --- Executes on button press in writeMfileBtn.
218 function writeMfileBtn_Callback(hObject, eventdata, handles)
219 % hObject handle to writeMfileBtn (see GCBO)
220 % eventdata reserved - to be defined in a future version of MATLAB
221 % handles structure with handles and user data (see GUIDATA)
222
223 % get model
224 model = get(handles.currentModelTxt, 'String');
225 % get m-file name
226 [filename, pathname, filteridx] = uiputfile('*.m', 'Save m-file as', [model '_mfile_.m']);
227
228 if ~isempty(filename)
229 mfile = fullfile(pathname, filename);
230 if sltpda_verify_model(model)
231 % parse model file
232 cmds = sltpda_parse_model(model);
233 % write m file
234 sltpda_cmds2m(model, cmds, mfile);
235 % edit
236 edit(mfile);
237 end
238 end
239
240 %--------------------------------------------------------------------------
241 % set the current block parameters
242 %
243 function setCurrentBlock(handles)
244
245 bh = get_param(gcb, 'handle');
246 cmd = getCmdFromHandle(bh, handles);
247 setappdata(handles.main, 'currentBlock', cmd)
248
249 try
250 set(handles.parametersHeaderTxt, 'String', ['Parameters for ' gcb]);
251
252 % get parameters from cmd structure
253 pl = cmd.plist;
254 plist = [];
255 for j=1:length(pl.params)
256 p = pl.params(j);
257 plist = [plist cellstr(p.key)];
258 end
259 set(handles.paramsList, 'String', plist);
260
261 catch
262 set(handles.parametersHeaderTxt, 'String', 'Parameters');
263 end
264
265 % --- Executes when user attempts to close main.
266 function main_CloseRequestFcn(hObject, eventdata, handles)
267 % hObject handle to main (see GCBO)
268 % eventdata reserved - to be defined in a future version of MATLAB
269 % handles structure with handles and user data (see GUIDATA)
270
271 % cbt = getappdata(handles.main, 'cbt');
272 % stop(cbt);
273 % delete(cbt);
274
275 csyst = getappdata(handles.main, 'csyst');
276 stop(csyst);
277 delete(csyst);
278
279 % Hint: delete(hObject) closes the figure
280 delete(hObject);
281
282
283 % --- Executes on button press in editLoopsBtn.
284 function editLoopsBtn_Callback(hObject, eventdata, handles)
285 % hObject handle to editLoopsBtn (see GCBO)
286 % eventdata reserved - to be defined in a future version of MATLAB
287 % handles structure with handles and user data (see GUIDATA)
288
289
290 % --- Executes on selection change in paramsList.
291 function paramsList_Callback(hObject, eventdata, handles)
292 % hObject handle to paramsList (see GCBO)
293 % eventdata reserved - to be defined in a future version of MATLAB
294 % handles structure with handles and user data (see GUIDATA)
295
296 % Hints: contents = get(hObject,'String') returns paramsList contents as cell array
297 % contents{get(hObject,'Value')} returns selected item from paramsList
298
299 keys = get(hObject, 'String');
300 key = keys{get(hObject,'Value')};
301
302 % get the current block
303 cmd = getappdata(handles.main, 'currentBlock')
304
305 p = find(cmd.plist, key)
306
307 if isnumeric(p)
308 set(handles.paramEdit, 'String', num2str(p));
309 elseif ischar(p)
310 set(handles.paramEdit, 'String', p);
311 elseif isa(p, 'specwin')
312 set(handles.paramEdit, 'String', p.name)
313 else
314 warning('!!! unknown parameter type.');
315 end
316
317
318 % --- Executes during object creation, after setting all properties.
319 function paramsList_CreateFcn(hObject, eventdata, handles)
320 % hObject handle to paramsList (see GCBO)
321 % eventdata reserved - to be defined in a future version of MATLAB
322 % handles empty - handles not created until after all CreateFcns called
323
324 % Hint: listbox controls usually have a white background on Windows.
325 % See ISPC and COMPUTER.
326 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
327 set(hObject,'BackgroundColor','white');
328 end
329
330
331
332 function paramEdit_Callback(hObject, eventdata, handles)
333 % hObject handle to paramEdit (see GCBO)
334 % eventdata reserved - to be defined in a future version of MATLAB
335 % handles structure with handles and user data (see GUIDATA)
336
337 % Hints: get(hObject,'String') returns contents of paramEdit as text
338 % str2double(get(hObject,'String')) returns contents of paramEdit as a double
339
340
341 % --- Executes during object creation, after setting all properties.
342 function paramEdit_CreateFcn(hObject, eventdata, handles)
343 % hObject handle to paramEdit (see GCBO)
344 % eventdata reserved - to be defined in a future version of MATLAB
345 % handles empty - handles not created until after all CreateFcns called
346
347 % Hint: edit controls usually have a white background on Windows.
348 % See ISPC and COMPUTER.
349 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
350 set(hObject,'BackgroundColor','white');
351 end
352
353
354 % --- Executes on selection change in loopList.
355 function loopList_Callback(hObject, eventdata, handles)
356 % hObject handle to loopList (see GCBO)
357 % eventdata reserved - to be defined in a future version of MATLAB
358 % handles structure with handles and user data (see GUIDATA)
359
360 % Hints: contents = get(hObject,'String') returns loopList contents as cell array
361 % contents{get(hObject,'Value')} returns selected item from loopList
362
363
364 % --- Executes during object creation, after setting all properties.
365 function loopList_CreateFcn(hObject, eventdata, handles)
366 % hObject handle to loopList (see GCBO)
367 % eventdata reserved - to be defined in a future version of MATLAB
368 % handles empty - handles not created until after all CreateFcns called
369
370 % Hint: listbox controls usually have a white background on Windows.
371 % See ISPC and COMPUTER.
372 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
373 set(hObject,'BackgroundColor','white');
374 end
375
376 %--------------------------------------------------------------------------
377 % get cmd from handle
378 function cmd = getCmdFromHandle(blockhandle, handles)
379
380 model = get(handles.currentModelTxt, 'String')
381 if sltpda_verify_model(model)
382 % parse model file
383 cmds = sltpda_parse_model(model);
384 for j=1:length(cmds)
385 if cmds(j).handle == blockhandle
386 cmd = cmds(j);
387 break;
388 end
389 end
390 end
391
392
393 % --- Executes on button press in loadCurrentBlock.
394 function loadCurrentBlock_Callback(hObject, eventdata, handles)
395 % hObject handle to loadCurrentBlock (see GCBO)
396 % eventdata reserved - to be defined in a future version of MATLAB
397 % handles structure with handles and user data (see GUIDATA)
398
399 setCurrentBlock(handles);
400
401
402 % --- Executes on button press in addLoopBtn.
403 function addLoopBtn_Callback(hObject, eventdata, handles)
404 % hObject handle to addLoopBtn (see GCBO)
405 % eventdata reserved - to be defined in a future version of MATLAB
406 % handles structure with handles and user data (see GUIDATA)
407
408 contents = get(handles.paramsList,'String');
409 key = contents{get(handles.paramsList,'Value')};
410
411 % Find this key in current block
412 cmd = getappdata(handles.main, 'currentBlock')
413
414 % make new loop
415 loop.block = cmd.name;
416 loop.handle = cmd.handle;
417 loop.key = key;
418 loop.values = get(handles.paramEdit, 'String');
419 loop.on = 1;
420
421 % get existing loops
422 loops = getappdata(handles.main, 'loops');
423
424 % add this loop
425 if ~isempty(loop.values)
426 loops = [loops loop];
427 setappdata(handles.main, 'loops', loops);
428 end
429
430
431 % set list
432 setLoopList(handles);
433
434
435 %--------------------------------------------------------------------------
436 % set loops into list
437 function setLoopList(handles)
438
439 loops = getappdata(handles.main, 'loops');
440
441 % build list of strings
442 objlist = [];
443 for j=1:length(loops)
444 l = loops(j);
445 if l.on
446 str = [sprintf('%s: %s ', l.block, l.key) num2str(l.values) ' on'];
447 else
448 str = [sprintf('%s: %s ', l.block, l.key) num2str(l.values) ' off'];
449 end
450 objlist = strvcat(objlist, str);
451
452 end
453
454 set(handles.loopList, 'String', objlist);
455 set(handles.loopList, 'Value', 1);
456
457
458 % --- Executes on button press in pzmodelGuiBtn.
459 function pzmodelGuiBtn_Callback(hObject, eventdata, handles)
460 % hObject handle to pzmodelGuiBtn (see GCBO)
461 % eventdata reserved - to be defined in a future version of MATLAB
462 % handles structure with handles and user data (see GUIDATA)
463
464 pzmodel_helper;
465
466
467 % --- Executes on button press in clearLoopsBtn.
468 function clearLoopsBtn_Callback(hObject, eventdata, handles)
469 % hObject handle to clearLoopsBtn (see GCBO)
470 % eventdata reserved - to be defined in a future version of MATLAB
471 % handles structure with handles and user data (see GUIDATA)
472
473 setappdata(handles.main, 'loops', []);
474
475 % set list
476 setLoopList(handles);
477
478
479 % --- Executes on button press in executeLoopsChk.
480 function executeLoopsChk_Callback(hObject, eventdata, handles)
481 % hObject handle to executeLoopsChk (see GCBO)
482 % eventdata reserved - to be defined in a future version of MATLAB
483 % handles structure with handles and user data (see GUIDATA)
484
485 % Hint: get(hObject,'Value') returns toggle state of executeLoopsChk
486
487
488 % --- Executes on button press in deleteLoops.
489 function deleteLoops_Callback(hObject, eventdata, handles)
490 % hObject handle to deleteLoops (see GCBO)
491 % eventdata reserved - to be defined in a future version of MATLAB
492 % handles structure with handles and user data (see GUIDATA)
493
494
495 % --- Executes on button press in loopOnOff.
496 function loopOnOff_Callback(hObject, eventdata, handles)
497 % hObject handle to loopOnOff (see GCBO)
498 % eventdata reserved - to be defined in a future version of MATLAB
499 % handles structure with handles and user data (see GUIDATA)
500
501 loops = getappdata(handles.main, 'loops');
502 vals = get(handles.loopList,'Value');
503
504 for j=1:vals
505 if loops(j).on
506 loops(j).on = 0;
507 else
508 loops(j).on = 1;
509 end
510 end
511
512 setappdata(handles.main, 'loops', loops);
513 setLoopList(handles);