PageRenderTime 28ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/ATF2/FlightSim/testApps/multiKnobs/multiKnobs_table.m

http://atf2flightsim.googlecode.com/
MATLAB | 409 lines | 201 code | 58 blank | 150 comment | 29 complexity | 412f4081188fdf9d637307e4b04d9854 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. function varargout = multiKnobs_table(varargin)
  2. % MULTIKNOBS_TABLE M-file for multiKnobs_table.fig
  3. % MULTIKNOBS_TABLE, by itself, creates a new MULTIKNOBS_TABLE or raises the existing
  4. % singleton*.
  5. %
  6. % H = MULTIKNOBS_TABLE returns the handle to a new MULTIKNOBS_TABLE or the handle to
  7. % the existing singleton*.
  8. %
  9. % MULTIKNOBS_TABLE('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in MULTIKNOBS_TABLE.M with the given input arguments.
  11. %
  12. % MULTIKNOBS_TABLE('Property','Value',...) creates a new MULTIKNOBS_TABLE or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before multiKnobs_table_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to multiKnobs_table_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. % Edit the above text to modify the response to help multiKnobs_table
  23. % Last Modified by GUIDE v2.5 23-Jun-2009 16:01:44
  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct('gui_Name', mfilename, ...
  27. 'gui_Singleton', gui_Singleton, ...
  28. 'gui_OpeningFcn', @multiKnobs_table_OpeningFcn, ...
  29. 'gui_OutputFcn', @multiKnobs_table_OutputFcn, ...
  30. 'gui_LayoutFcn', [] , ...
  31. 'gui_Callback', []);
  32. if nargin && ischar(varargin{1})
  33. gui_State.gui_Callback = str2func(varargin{1});
  34. end
  35. if nargout
  36. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38. gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT
  41. % --- Executes just before multiKnobs_table is made visible.
  42. function multiKnobs_table_OpeningFcn(hObject, eventdata, handles, varargin)
  43. % This function has no output args, see OutputFcn.
  44. % hObject handle to figure
  45. % eventdata reserved - to be defined in a future version of MATLAB
  46. % handles structure with handles and user data (see GUIDATA)
  47. % varargin command line arguments to multiKnobs_table (see VARARGIN)
  48. % Choose default command line output for multiKnobs_table
  49. handles.output = handles;
  50. % Update data
  51. edit1_Callback(handles.edit1,[],handles);
  52. % Update handles structure
  53. guidata(hObject, handles);
  54. % UIWAIT makes multiKnobs_table wait for user response (see UIRESUME)
  55. % uiwait(handles.figure1);
  56. % --- Outputs from this function are returned to the command line.
  57. function varargout = multiKnobs_table_OutputFcn(hObject, eventdata, handles)
  58. % varargout cell array for returning output args (see VARARGOUT);
  59. % hObject handle to figure
  60. % eventdata reserved - to be defined in a future version of MATLAB
  61. % handles structure with handles and user data (see GUIDATA)
  62. % Get default command line output from handles structure
  63. varargout{1} = handles.output;
  64. % --- Delete Table
  65. function pushbutton1_Callback(hObject, eventdata, handles)
  66. % hObject handle to pushbutton1 (see GCBO)
  67. % eventdata reserved - to be defined in a future version of MATLAB
  68. % handles structure with handles and user data (see GUIDATA)
  69. global FL
  70. if ~strcmp(questdlg('Delete this table?','Table Delete Request'),'Yes')
  71. return
  72. end
  73. if strcmp(get(handles.edit1,'String'),'Default')
  74. errordlg('Cannot delete the default table','Delete table error')
  75. return
  76. end
  77. stat=multiKnobsFn('DeleteTable',get(handles.edit1,'String'));
  78. if stat{1}~=1
  79. errordlg(stat{2},'Delete Table Error')
  80. return
  81. end
  82. [stat,pars]=multiKnobsFn('GetPars');
  83. set(FL.Gui.multiKnobs_edit.popupmenu2,'String',pars.tableNames);
  84. if isfield(FL.Gui,'multiKnobs_edit') && ishandle(FL.Gui.multiKnobs_edit.figure1)
  85. set(FL.Gui.multiKnobs_edit.popupmenu2,'Value',1)
  86. end
  87. set(handles.edit1,'String','NewTable')
  88. edit1_Callback(handles.edit1,[],handles)
  89. % --- Quit
  90. function pushbutton6_Callback(hObject, eventdata, handles)
  91. % hObject handle to pushbutton6 (see GCBO)
  92. % eventdata reserved - to be defined in a future version of MATLAB
  93. % handles structure with handles and user data (see GUIDATA)
  94. global FL
  95. if isfield(FL.Gui,'multiKnobs_edit') && ishandle(FL.Gui.multiKnobs_edit.figure1)
  96. multiKnobs_edit('pushbutton11_Callback',FL.Gui.multiKnobs_edit.pushbutton11,[],FL.Gui.multiKnobs_edit)
  97. [stat,pars]=multiKnobsFn('GetPars');
  98. set(FL.Gui.multiKnobs_edit.popupmenu2,'String',pars.tableNames);
  99. tlist=get(FL.Gui.multiKnobs_edit.popupmenu2,'String');
  100. if any(strcmp(tlist,get(handles.edit1,'String')))
  101. set(FL.Gui.multiKnobs_edit.popupmenu2,'Value',find(strcmp(tlist,get(handles.edit1,'String'))))
  102. end
  103. end
  104. guiCloseFn('multiKnobs_table',handles);
  105. % --- Executes on button press in pushbutton7.
  106. function pushbutton7_Callback(hObject, eventdata, handles)
  107. % hObject handle to pushbutton7 (see GCBO)
  108. % eventdata reserved - to be defined in a future version of MATLAB
  109. % handles structure with handles and user data (see GUIDATA)
  110. % --- Interpolation method
  111. function popupmenu1_Callback(hObject, eventdata, handles)
  112. % hObject handle to popupmenu1 (see GCBO)
  113. % eventdata reserved - to be defined in a future version of MATLAB
  114. % handles structure with handles and user data (see GUIDATA)
  115. klist=get(hObject,'String');
  116. tStruc.interpMethod=klist{get(hObject,'Value')};
  117. stat=multiKnobsFn('EditTableStruc',get(handles.edit1,'String'),tStruc);
  118. if stat{1}~=1
  119. errordlg(stat{2},'Error editing table structure')
  120. end
  121. edit1_Callback(handles.edit1,[],handles);
  122. % --- Executes during object creation, after setting all properties.
  123. function popupmenu1_CreateFcn(hObject, eventdata, handles)
  124. % hObject handle to popupmenu1 (see GCBO)
  125. % eventdata reserved - to be defined in a future version of MATLAB
  126. % handles empty - handles not created until after all CreateFcns called
  127. % Hint: popupmenu controls usually have a white background on Windows.
  128. % See ISPC and COMPUTER.
  129. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  130. set(hObject,'BackgroundColor','white');
  131. end
  132. % --- Use extrapolation
  133. function checkbox1_Callback(hObject, eventdata, handles)
  134. % hObject handle to checkbox1 (see GCBO)
  135. % eventdata reserved - to be defined in a future version of MATLAB
  136. % handles structure with handles and user data (see GUIDATA)
  137. tStruc.doExtrap=get(hObject,'Value');
  138. stat=multiKnobsFn('EditTableStruc',get(handles.edit1,'String'),tStruc);
  139. if stat{1}~=1
  140. errordlg(stat{2},'Error editing table structure')
  141. end
  142. edit1_Callback(handles.edit1,[],handles);
  143. function edit2_Callback(hObject, eventdata, handles)
  144. % hObject handle to edit2 (see GCBO)
  145. % eventdata reserved - to be defined in a future version of MATLAB
  146. % handles structure with handles and user data (see GUIDATA)
  147. % Hints: get(hObject,'String') returns contents of edit2 as text
  148. % str2double(get(hObject,'String')) returns contents of edit2 as a double
  149. if isnan(str2double(get(hObject,'String')))
  150. errordlg('Bad input','Knob Value Error')
  151. set(hObject,'String','')
  152. end
  153. % --- Executes during object creation, after setting all properties.
  154. function edit2_CreateFcn(hObject, eventdata, handles)
  155. % hObject handle to edit2 (see GCBO)
  156. % eventdata reserved - to be defined in a future version of MATLAB
  157. % handles empty - handles not created until after all CreateFcns called
  158. % Hint: edit controls usually have a white background on Windows.
  159. % See ISPC and COMPUTER.
  160. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  161. set(hObject,'BackgroundColor','white');
  162. end
  163. function edit3_Callback(hObject, eventdata, handles)
  164. % hObject handle to edit3 (see GCBO)
  165. % eventdata reserved - to be defined in a future version of MATLAB
  166. % handles structure with handles and user data (see GUIDATA)
  167. % Hints: get(hObject,'String') returns contents of edit3 as text
  168. % str2double(get(hObject,'String')) returns contents of edit3 as a double
  169. if isnan(str2double(get(hObject,'String')))
  170. errordlg('Bad input','Lookup Value Error')
  171. set(hObject,'String','')
  172. end
  173. % --- Executes during object creation, after setting all properties.
  174. function edit3_CreateFcn(hObject, eventdata, handles) %#ok<*INUSD>
  175. % hObject handle to edit3 (see GCBO)
  176. % eventdata reserved - to be defined in a future version of MATLAB
  177. % handles empty - handles not created until after all CreateFcns called
  178. % Hint: edit controls usually have a white background on Windows.
  179. % See ISPC and COMPUTER.
  180. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  181. set(hObject,'BackgroundColor','white');
  182. end
  183. % --- add button
  184. function pushbutton5_Callback(hObject, eventdata, handles) %#ok<*INUSL,*DEFNU>
  185. % hObject handle to pushbutton5 (see GCBO)
  186. % eventdata reserved - to be defined in a future version of MATLAB
  187. % handles structure with handles and user data (see GUIDATA)
  188. kVal=str2double(get(handles.edit2,'String'));
  189. lVal=str2double(get(handles.edit3,'String'));
  190. if isnan(kVal) || isnan(lVal)
  191. errordlg('Bad knob value and/or lookup value inputs','Add row error')
  192. return
  193. end
  194. tStruc.kVal=kVal;
  195. tStruc.lVal=lVal;
  196. klist=get(handles.popupmenu1,'String');
  197. tStruc.interpMethod=klist{get(handles.popupmenu1,'Value')};
  198. tStruc.doExtrap=get(handles.checkbox1,'Value');
  199. stat=multiKnobsFn('MakeTableEntry',get(handles.edit1,'String'),tStruc);
  200. if stat{1}~=1
  201. errordlg(stat{2},'Make Table Entry Error')
  202. return
  203. end
  204. edit1_Callback(handles.edit1,[],handles);
  205. % --- Executes on selection change in listbox1.
  206. function listbox1_Callback(hObject, eventdata, handles)
  207. % hObject handle to listbox1 (see GCBO)
  208. % eventdata reserved - to be defined in a future version of MATLAB
  209. % handles structure with handles and user data (see GUIDATA)
  210. % Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
  211. % contents{get(hObject,'Value')} returns selected item from listbox1
  212. % --- Executes during object creation, after setting all properties.
  213. function listbox1_CreateFcn(hObject, eventdata, handles)
  214. % hObject handle to listbox1 (see GCBO)
  215. % eventdata reserved - to be defined in a future version of MATLAB
  216. % handles empty - handles not created until after all CreateFcns called
  217. % Hint: listbox controls usually have a white background on Windows.
  218. % See ISPC and COMPUTER.
  219. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  220. set(hObject,'BackgroundColor','white');
  221. end
  222. % --- Delete row
  223. function pushbutton2_Callback(hObject, eventdata, handles)
  224. % hObject handle to pushbutton2 (see GCBO)
  225. % eventdata reserved - to be defined in a future version of MATLAB
  226. % handles structure with handles and user data (see GUIDATA)
  227. if ~strcmp(questdlg('Delete Table entry/entries?','Table entry delete request'),'Yes')
  228. return
  229. end
  230. dvals=get(handles.listbox1,'Value');
  231. stat=multiKnobsFn('DeleteTableEntry',get(handles.edit1,'String'),dvals);
  232. if stat{1}~=1
  233. errodlg(stat{2},'Table Entry Deletion error')
  234. end
  235. set(handles.listbox1,'Value',1)
  236. edit1_Callback(handles.edit1,[],handles)
  237. % --- Display data
  238. function pushbutton3_Callback(hObject, eventdata, handles)
  239. % hObject handle to pushbutton3 (see GCBO)
  240. % eventdata reserved - to be defined in a future version of MATLAB
  241. % handles structure with handles and user data (see GUIDATA)
  242. global FL
  243. if isfield(FL.Gui,'multiKnobs_table_plot1') && ishandle(FL.Gui.multiKnobs_table_plot1)
  244. figure(FL.Gui.multiKnobs_table_plot1)
  245. else
  246. FL.Gui.multiKnobs_table_plot1=figure;
  247. end
  248. [stat pars]=multiKnobsFn('GetPars');
  249. tname=get(handles.edit1,'String');
  250. plot(pars.table.(tname).kVal,pars.table.(tname).lVal,'bo')
  251. title('Lookup table values')
  252. xlabel('Knob Value')
  253. ylabel('Lookup Value')
  254. if get(handles.togglebutton1,'Value')
  255. hold on
  256. xx=linspace(pars.table.(tname).kVal(1),pars.table.(tname).kVal(end),10000);
  257. yy=interp1(pars.table.(tname).kVal,pars.table.(tname).lVal,xx,pars.table.(tname).interpMethod);
  258. plot(xx,yy,'r')
  259. hold off
  260. end
  261. % --- Update data from figure
  262. function pushbutton4_Callback(hObject, eventdata, handles)
  263. % hObject handle to pushbutton4 (see GCBO)
  264. % eventdata reserved - to be defined in a future version of MATLAB
  265. % handles structure with handles and user data (see GUIDATA)
  266. global FL
  267. if isfield(FL.Gui,'multiKnobs_table_plot1') && ishandle(FL.Gui.multiKnobs_table_plot1)
  268. set(handles.listbox1,'Value',1)
  269. fhan=get(FL.Gui.multiKnobs_table_plot1,'Children');
  270. ahan=get(fhan,'Children');
  271. data(1,:)=get(ahan{end},'XData');
  272. data(2,:)=get(ahan{end},'Ydata');
  273. newdata(1,:)=data(1,~isnan(data(2,:)));
  274. newdata(2,:)=data(2,~isnan(data(2,:)));
  275. stat=multiKnobsFn('SetTableData',get(handles.edit1,'String'),newdata);
  276. if stat{1}~=1
  277. errordlg(stat{2},'Table Data Edit Error')
  278. return
  279. end
  280. pushbutton3_Callback(handles.pushbutton3,[],handles);
  281. [stat, pars]=multiKnobsFn('GetPars');
  282. tname=get(handles.edit1,'String');
  283. set(handles.listbox1,'Value',1)
  284. set(handles.listbox1,'String',pars.table.(tname).text);
  285. end
  286. % --- Show interpolation data
  287. function togglebutton1_Callback(hObject, eventdata, handles)
  288. % hObject handle to togglebutton1 (see GCBO)
  289. % eventdata reserved - to be defined in a future version of MATLAB
  290. % handles structure with handles and user data (see GUIDATA)
  291. % global FL
  292. %
  293. % if get(hObject,'Value') && isfield(FL.Gui,'multiKnobs_table_plot1') && ishandle(FL.Gui.multiKnobs_table_plot1)
  294. % figure(FL.Gui.multiKnobs_table_plot1)
  295. % hold on
  296. % xx=linspace(pars.kVal(1),pars.kVal(end),10000);
  297. % yy=interp1(pars.kVal,pars.lVal,xx,pars.interpMethod);
  298. % plot(xx,yy,'r')
  299. % hold off
  300. % elseif isfield(FL.Gui,'multiKnobs_table_plot1') && ishandle(FL.Gui.multiKnobs_table_plot1)
  301. % fhan=get(FL.Gui.multiKnobs_table_plot1,'Children');
  302. % ahan=get(fhan,'Children');
  303. % if length(ahan)==2
  304. % delete(ahan(1))
  305. % end
  306. % end
  307. pushbutton3_Callback(handles.pushbutton3,[],handles);
  308. function edit1_Callback(hObject, eventdata, handles)
  309. % hObject handle to edit1 (see GCBO)
  310. % eventdata reserved - to be defined in a future version of MATLAB
  311. % handles structure with handles and user data (see GUIDATA)
  312. if ~isempty(regexp(get(hObject,'String'),'\W', 'once'))
  313. errordlg('No spaces or symbols allowed in name')
  314. return
  315. end
  316. [stat pars]=multiKnobsFn('GetPars');
  317. tableName=get(hObject,'String');
  318. intlist=get(handles.popupmenu1,'String');
  319. if any(strcmp(tableName,pars.tableNames)) && ~strcmp(pars.table.(tableName).text{1},'<none>')
  320. set(handles.listbox1,'String',pars.table.(tableName).text)
  321. set(handles.popupmenu1,'Value',find(strcmp(intlist,pars.table.(tableName).interpMethod)))
  322. set(handles.checkbox1,'Value',pars.table.(tableName).doExtrap)
  323. else
  324. set(handles.listbox1,'String','<none>')
  325. set(handles.popupmenu1,'Value',2)
  326. set(handles.checkbox1,'Value',0)
  327. end
  328. % --- Executes during object creation, after setting all properties.
  329. function edit1_CreateFcn(hObject, eventdata, handles)
  330. % hObject handle to edit1 (see GCBO)
  331. % eventdata reserved - to be defined in a future version of MATLAB
  332. % handles empty - handles not created until after all CreateFcns called
  333. % Hint: edit controls usually have a white background on Windows.
  334. % See ISPC and COMPUTER.
  335. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  336. set(hObject,'BackgroundColor','white');
  337. end
  338. % --- Executes when user attempts to close figure1.
  339. function figure1_CloseRequestFcn(hObject, eventdata, handles)
  340. % hObject handle to figure1 (see GCBO)
  341. % eventdata reserved - to be defined in a future version of MATLAB
  342. % handles structure with handles and user data (see GUIDATA)
  343. global FL
  344. if isfield(FL.Gui,'multiKnobs_edit') && ishandle(FL.Gui.multiKnobs_edit)
  345. multiKnobs_edit('pushbutton11_Callback',FL.Gui.multiKnobs_edit.pushbutton11,[],FL.Gui.multiKnobs_edit)
  346. tlist=get(FL.Gui.multiKnobs_edit.popupmenu2,'String');
  347. if any(strcmp(tlist,get(handles.edit1,'String')))
  348. set(FL.Gui.multiKnobs_edit.popupmenu2,'Value',find(strcmp(tlist,get(handles.edit1,'String'))))
  349. end
  350. end
  351. guiCloseFn('multiKnobs_table',handles);