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

/ATF2/FlightSim/coreApps/FAS_main.m

http://atf2flightsim.googlecode.com/
MATLAB | 455 lines | 239 code | 59 blank | 157 comment | 21 complexity | 5a31744afd80022dd52a114a0218edc0 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. function varargout = FAS_main(varargin)
  2. % FAS_MAIN M-file for FAS_main.fig
  3. % FAS_MAIN, by itself, creates a new FAS_MAIN or raises the existing
  4. % singleton*.
  5. %
  6. % H = FAS_MAIN returns the handle to a new FAS_MAIN or the handle to
  7. % the existing singleton*.
  8. %
  9. % FAS_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in FAS_MAIN.M with the given input arguments.
  11. %
  12. % FAS_MAIN('Property','Value',...) creates a new FAS_MAIN or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before FAS_main_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to FAS_main_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 FAS_main
  23. % Last Modified by GUIDE v2.5 27-Mar-2009 13:38:23
  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', @FAS_main_OpeningFcn, ...
  29. 'gui_OutputFcn', @FAS_main_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 FAS_main is made visible.
  42. function FAS_main_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 FAS_main (see VARARGIN)
  48. % Choose default command line output for FAS_main
  49. handles.output = handles;
  50. % Update handles structure
  51. guidata(hObject, handles);
  52. % UIWAIT makes FAS_main wait for user response (see UIRESUME)
  53. % uiwait(handles.figure1);
  54. % --- Outputs from this function are returned to the command line.
  55. function varargout = FAS_main_OutputFcn(hObject, eventdata, handles)
  56. % varargout cell array for returning output args (see VARARGOUT);
  57. % hObject handle to figure
  58. % eventdata reserved - to be defined in a future version of MATLAB
  59. % handles structure with handles and user data (see GUIDATA)
  60. % Get default command line output from handles structure
  61. varargout{1} = handles.output;
  62. % --- Executes on selection change in listbox2.
  63. function listbox2_Callback(hObject, eventdata, handles)
  64. % hObject handle to listbox2 (see GCBO)
  65. % eventdata reserved - to be defined in a future version of MATLAB
  66. % handles structure with handles and user data (see GUIDATA)
  67. % Hints: contents = get(hObject,'String') returns listbox2 contents as cell array
  68. % contents{get(hObject,'Value')} returns selected item from listbox2
  69. % --- Executes during object creation, after setting all properties.
  70. function listbox2_CreateFcn(hObject, eventdata, handles)
  71. % hObject handle to listbox2 (see GCBO)
  72. % eventdata reserved - to be defined in a future version of MATLAB
  73. % handles empty - handles not created until after all CreateFcns called
  74. % Hint: listbox controls usually have a white background on Windows.
  75. % See ISPC and COMPUTER.
  76. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  77. set(hObject,'BackgroundColor','white');
  78. end
  79. % --- Executes on button press in pushbutton3.
  80. function pushbutton3_Callback(hObject, eventdata, handles)
  81. % hObject handle to pushbutton3 (see GCBO)
  82. % eventdata reserved - to be defined in a future version of MATLAB
  83. % handles structure with handles and user data (see GUIDATA)
  84. allowDeny('allow',handles);
  85. % --- Executes on button press in pushbutton4.
  86. function pushbutton4_Callback(hObject, eventdata, handles)
  87. % hObject handle to pushbutton4 (see GCBO)
  88. % eventdata reserved - to be defined in a future version of MATLAB
  89. % handles structure with handles and user data (see GUIDATA)
  90. allowDeny('allow_all',handles);
  91. % --- Executes on button press in pushbutton5.
  92. function pushbutton5_Callback(hObject, eventdata, handles)
  93. % hObject handle to pushbutton5 (see GCBO)
  94. % eventdata reserved - to be defined in a future version of MATLAB
  95. % handles structure with handles and user data (see GUIDATA)
  96. allowDeny('deny',handles);
  97. % --- Executes on button press in pushbutton6.
  98. function pushbutton6_Callback(hObject, eventdata, handles)
  99. % hObject handle to pushbutton6 (see GCBO)
  100. % eventdata reserved - to be defined in a future version of MATLAB
  101. % handles structure with handles and user data (see GUIDATA)
  102. allowDeny('deny_all',handles);
  103. % --- Executes on button press in togglebutton1.
  104. function togglebutton1_Callback(hObject, eventdata, handles)
  105. % hObject handle to togglebutton1 (see GCBO)
  106. % eventdata reserved - to be defined in a future version of MATLAB
  107. % handles structure with handles and user data (see GUIDATA)
  108. global FL
  109. % Hint: get(hObject,'Value') returns toggle state of togglebutton1
  110. if get(hObject,'Value')==1
  111. if FL.SimMode
  112. set(hObject,'BackGroundColor','cyan');
  113. else
  114. switch lower(questdlg('Auto Reply to all incoming requests?'))
  115. case 'yes'
  116. set(hObject,'BackGroundColor','cyan');
  117. otherwise
  118. set(hObject,'Value',0);
  119. set(hObject,'BackGroundColor',[204,204,204]./256);
  120. end % switch question
  121. end % if sim mode
  122. else
  123. set(hObject,'BackGroundColor',[204,204,204]./256);
  124. end % if push on
  125. % --- Executes on selection change in popupmenu1.
  126. function popupmenu1_Callback(hObject, eventdata, handles)
  127. % hObject handle to popupmenu1 (see GCBO)
  128. % eventdata reserved - to be defined in a future version of MATLAB
  129. % handles structure with handles and user data (see GUIDATA)
  130. % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
  131. % contents{get(hObject,'Value')} returns selected item from popupmenu1
  132. % --- Executes during object creation, after setting all properties.
  133. function popupmenu1_CreateFcn(hObject, eventdata, handles)
  134. % hObject handle to popupmenu1 (see GCBO)
  135. % eventdata reserved - to be defined in a future version of MATLAB
  136. % handles empty - handles not created until after all CreateFcns called
  137. % Hint: popupmenu controls usually have a white background on Windows.
  138. % See ISPC and COMPUTER.
  139. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  140. set(hObject,'BackgroundColor','white');
  141. end
  142. % --- Executes on button press in togglebutton2.
  143. function togglebutton2_Callback(hObject, eventdata, handles)
  144. % hObject handle to togglebutton2 (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. % Hint: get(hObject,'Value') returns toggle state of togglebutton2
  148. if get(hObject,'Value')==1
  149. switch lower(questdlg('Apply Timeout to all approved requests?'))
  150. case 'yes'
  151. set(hObject,'BackgroundColor',[255,177,100]./256);
  152. otherwise
  153. set(hObject,'Value',0);
  154. set(hObject,'BackgroundColor',[204,204,204]./256);
  155. end % switch question
  156. else
  157. set(hObject,'BackGroundColor',[204,204,204]./256);
  158. end % if push on
  159. function edit1_Callback(hObject, eventdata, handles)
  160. % hObject handle to edit1 (see GCBO)
  161. % eventdata reserved - to be defined in a future version of MATLAB
  162. % handles structure with handles and user data (see GUIDATA)
  163. % Hints: get(hObject,'String') returns contents of edit1 as text
  164. % str2double(get(hObject,'String')) returns contents of edit1 as a double
  165. % --- Executes during object creation, after setting all properties.
  166. function edit1_CreateFcn(hObject, eventdata, handles)
  167. % hObject handle to edit1 (see GCBO)
  168. % eventdata reserved - to be defined in a future version of MATLAB
  169. % handles empty - handles not created until after all CreateFcns called
  170. % Hint: edit controls usually have a white background on Windows.
  171. % See ISPC and COMPUTER.
  172. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  173. set(hObject,'BackgroundColor','white');
  174. end
  175. % --- Executes on selection change in popupmenu2.
  176. function popupmenu2_Callback(hObject, eventdata, handles)
  177. % hObject handle to popupmenu2 (see GCBO)
  178. % eventdata reserved - to be defined in a future version of MATLAB
  179. % handles structure with handles and user data (see GUIDATA)
  180. % Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
  181. % contents{get(hObject,'Value')} returns selected item from popupmenu2
  182. % --- Executes during object creation, after setting all properties.
  183. function popupmenu2_CreateFcn(hObject, eventdata, handles)
  184. % hObject handle to popupmenu2 (see GCBO)
  185. % eventdata reserved - to be defined in a future version of MATLAB
  186. % handles empty - handles not created until after all CreateFcns called
  187. % Hint: popupmenu controls usually have a white background on Windows.
  188. % See ISPC and COMPUTER.
  189. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  190. set(hObject,'BackgroundColor','white');
  191. end
  192. % --- Executes on selection change in listbox1.
  193. function listbox1_Callback(hObject, eventdata, handles) %#ok<*INUSD>
  194. % hObject handle to listbox1 (see GCBO)
  195. % eventdata reserved - to be defined in a future version of MATLAB
  196. % handles structure with handles and user data (see GUIDATA)
  197. % Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
  198. % contents{get(hObject,'Value')} returns selected item from listbox1
  199. % --- Executes during object creation, after setting all properties.
  200. function listbox1_CreateFcn(hObject, eventdata, handles)
  201. % hObject handle to listbox1 (see GCBO)
  202. % eventdata reserved - to be defined in a future version of MATLAB
  203. % handles empty - handles not created until after all CreateFcns called
  204. % Hint: listbox controls usually have a white background on Windows.
  205. % See ISPC and COMPUTER.
  206. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  207. set(hObject,'BackgroundColor','white');
  208. end
  209. % --- Executes on button press in pushbutton1.
  210. function pushbutton1_Callback(hObject, eventdata, handles)
  211. % hObject handle to pushbutton1 (see GCBO)
  212. % eventdata reserved - to be defined in a future version of MATLAB
  213. % handles structure with handles and user data (see GUIDATA)
  214. global FL
  215. % ----------------------------------------
  216. % Clear selected item(s) from allowed list
  217. % ----------------------------------------
  218. % Get selected items to remove
  219. try
  220. guiList=get(handles.listbox1,'String');
  221. if ~iscell(guiList); guiList={guiList}; end;
  222. rmList=get(handles.listbox1,'Value');
  223. % Get user/req id
  224. for i_rmList=1:length(rmList)
  225. t=regexp(guiList{rmList(i_rmList)},'(.+)\s:\s(.+)\s:\s(.+):(.+)\s:\s(.+)','tokens');
  226. if ~isempty(t) && isfield(FL.AS,t{1}{3})
  227. FL.AS.(t{1}{3})=rmfield(FL.AS.(t{1}{3}),t{1}{4});
  228. end
  229. end % for i_rmList
  230. guiList={guiList{~ismember(1:length(guiList),rmList)}}';
  231. set(handles.listbox1,'String',guiList);
  232. set(handles.listbox1,'Value',1);
  233. catch
  234. error('Error clearing item from list: %s',lasterr)
  235. end
  236. % --- Executes on button press in pushbutton2.
  237. function pushbutton2_Callback(hObject, eventdata, handles) %#ok<*INUSL,*DEFNU>
  238. % hObject handle to pushbutton2 (see GCBO)
  239. % eventdata reserved - to be defined in a future version of MATLAB
  240. % handles structure with handles and user data (see GUIDATA)
  241. % global FL
  242. % ----------------------------------------
  243. % Clear all items from allowed list
  244. % ----------------------------------------
  245. set(handles.listbox1,'Value',1:length(get(handles.listbox1,'String')));
  246. pushbutton1_Callback(handles.pushbutton1, eventdata, handles)
  247. % userList=fieldnames(FL.AS);
  248. % for iuser=1:length(userList)
  249. % if ~isempty(regexp(userList{iuser},'^user', 'once' ))
  250. % FL.AS=rmfield(FL.AS,userList{iuser});
  251. % end % if user field
  252. % end % for iuser
  253. % set(handles.listbox1,'Value',1);
  254. % set(handles.listbox1,'String','');
  255. function allowDeny(opt,handles)
  256. global FL
  257. % ----------------------------------------
  258. % Allow selected items from request list
  259. % ----------------------------------------
  260. % Get selected items AS.pvListReq
  261. newReq=get(handles.listbox2,'String');
  262. approvedReq=get(handles.listbox1,'String');
  263. if isequal(opt,'allow') || isequal(opt,'deny')
  264. reqListSel=get(handles.listbox2,'Value');
  265. else
  266. reqListSel=1:length(newReq);
  267. end % if list or all
  268. % Deal with request
  269. if ~isempty(reqListSel)
  270. for iList=reqListSel
  271. % Get request data
  272. t=regexp(newReq{iList},'(.+)\s:\s(.+)\s:\s(.+):(.+)\s:\s(.+)','tokens');
  273. % Add to approved list and flag access allowed in FL struct
  274. if isfield(FL.AS,t{1}{3}) && isfield(FL.AS.(t{1}{3}),t{1}{4})
  275. if isequal(opt,'allow') || isequal(opt,'allow_all')
  276. approvedReq{end+1}=newReq{iList};
  277. FL.AS.(t{1}{3}).(t{1}{4}).access=true;
  278. else
  279. FL.AS.(t{1}{3}).(t{1}{4}).access=false;
  280. end % if allowing
  281. newReq={newReq{~ismember(reqListSel,iList)}}';
  282. else
  283. error(['No FL.AS entry for: ',t{1}{3},':',t{1}{4}]);
  284. end % if field names added to FL.AS
  285. end % for iList
  286. end % if ~empty
  287. % Update Req and pv name lists
  288. set(handles.listbox2,'Value',1);
  289. set(handles.listbox2,'String',newReq);
  290. if isequal(opt,'allow') || isequal(opt,'allow_all')
  291. set(handles.listbox1,'Value',1);
  292. set(handles.listbox1,'String',approvedReq);
  293. end % if allowing
  294. % --- Executes on button press in pushbutton7.
  295. function pushbutton7_Callback(hObject, eventdata, handles)
  296. % hObject handle to pushbutton7 (see GCBO)
  297. % eventdata reserved - to be defined in a future version of MATLAB
  298. % handles structure with handles and user data (see GUIDATA)
  299. global FL
  300. % --- Request Run access server
  301. if ~isequal(get(FL.AS.t_main,'Running'),'on')
  302. start(FL.AS.t_main);
  303. end % start as timer if not running
  304. % --- Executes on selection change in listbox3.
  305. function listbox3_Callback(hObject, eventdata, handles)
  306. % hObject handle to listbox3 (see GCBO)
  307. % eventdata reserved - to be defined in a future version of MATLAB
  308. % handles structure with handles and user data (see GUIDATA)
  309. % Hints: contents = get(hObject,'String') returns listbox3 contents as cell array
  310. % contents{get(hObject,'Value')} returns selected item from listbox3
  311. % --- Executes during object creation, after setting all properties.
  312. function listbox3_CreateFcn(hObject, eventdata, handles)
  313. % hObject handle to listbox3 (see GCBO)
  314. % eventdata reserved - to be defined in a future version of MATLAB
  315. % handles empty - handles not created until after all CreateFcns called
  316. % Hint: listbox controls usually have a white background on Windows.
  317. % See ISPC and COMPUTER.
  318. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  319. set(hObject,'BackgroundColor','white');
  320. end
  321. % --- Executes on button press in pushbutton10.
  322. function pushbutton10_Callback(hObject, eventdata, handles)
  323. % hObject handle to pushbutton10 (see GCBO)
  324. % eventdata reserved - to be defined in a future version of MATLAB
  325. % handles structure with handles and user data (see GUIDATA)
  326. % get access request list for this entry and display
  327. global FL BEAMLINE GIRDER PS
  328. % get access request list for this entry and display
  329. set(handles.listbox3,'Value',1)
  330. val=get(handles.listbox2,'Value');
  331. str=get(handles.listbox2,'String');
  332. t=regexp(str{val},'(.+)\s:\s(.+)\s:\s(.+):(.+)\s:\s(.+)','tokens');
  333. accStr={};
  334. if isfield(FL.AS.(t{1}{3}).(t{1}{4}),'PS')
  335. for iPS=1:length(FL.AS.(t{1}{3}).(t{1}{4}).PS)
  336. nPS=FL.AS.(t{1}{3}).(t{1}{4}).PS(iPS);
  337. accStr{end+1}=['PS',num2str(nPS),': ',BEAMLINE{PS(nPS).Element(1)}.Name];
  338. end % for iPS
  339. elseif isfield(FL.AS.(t{1}{3}).(t{1}{4}),'GIRDER')
  340. for iGIRDER=1:length(FL.AS.(t{1}{3}).(t{1}{4}).GIRDER)
  341. nGIRDER=FL.AS.(t{1}{3}).(t{1}{4}).GIRDER(iGIRDER);
  342. accStr{end+1}=['GIRDER',num2str(nGIRDER),': ',BEAMLINE{GIRDER{nGIRDER}.Element(1)}.Name];
  343. end % for iGIRDER
  344. end % if PS | GIRDER
  345. set(handles.listbox3,'String',accStr);
  346. % --- Executes on button press in pushbutton8.
  347. function pushbutton8_Callback(hObject, eventdata, handles)
  348. % hObject handle to pushbutton8 (see GCBO)
  349. % eventdata reserved - to be defined in a future version of MATLAB
  350. % handles structure with handles and user data (see GUIDATA)
  351. global FL BEAMLINE GIRDER PS
  352. % get access request list for this entry and display
  353. set(handles.listbox3,'Value',1)
  354. val=get(handles.listbox1,'Value');
  355. str=get(handles.listbox1,'String');
  356. t=regexp(str{val},'(.+)\s:\s(.+)\s:\s(.+):(.+)\s:\s(.+)','tokens');
  357. accStr={};
  358. if isfield(FL.AS.(t{1}{3}).(t{1}{4}),'PS')
  359. for iPS=1:length(FL.AS.(t{1}{3}).(t{1}{4}).PS)
  360. nPS=FL.AS.(t{1}{3}).(t{1}{4}).PS(iPS);
  361. accStr{end+1}=['PS',num2str(nPS),': ',BEAMLINE{PS(nPS).Element(1)}.Name];
  362. end % for iPS
  363. end % if ps
  364. if isfield(FL.AS.(t{1}{3}).(t{1}{4}),'GIRDER')
  365. for iGIRDER=1:length(FL.AS.(t{1}{3}).(t{1}{4}).GIRDER)
  366. nGIRDER=FL.AS.(t{1}{3}).(t{1}{4}).GIRDER(iGIRDER);
  367. accStr{end+1}=['GIRDER',num2str(nGIRDER),': ',BEAMLINE{GIRDER{nGIRDER}.Element(1)}.Name];
  368. end % for iGIRDER
  369. end % if GIRDER
  370. set(handles.listbox3,'String',accStr);
  371. % --- Executes when user attempts to close figure1.
  372. function figure1_CloseRequestFcn(hObject, eventdata, handles)
  373. % hObject handle to figure1 (see GCBO)
  374. % eventdata reserved - to be defined in a future version of MATLAB
  375. % handles structure with handles and user data (see GUIDATA)
  376. global FL
  377. stop(FL.AS.t_main);
  378. % Hint: delete(hObject) closes the figure
  379. delete(hObject);