PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/ATF2/FlightSim/coreApps/FlGui_test.m

http://atf2flightsim.googlecode.com/
MATLAB | 407 lines | 185 code | 80 blank | 142 comment | 34 complexity | f8adaaefff3bf3463f5913da9e7f3949 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. function varargout = FlGui_test(varargin)
  2. % FLGUI_TEST M-file for FlGui_test.fig
  3. % FLGUI_TEST, by itself, creates a new FLGUI_TEST or raises the existing
  4. % singleton*.
  5. %
  6. % H = FLGUI_TEST returns the handle to a new FLGUI_TEST or the handle to
  7. % the existing singleton*.
  8. %
  9. % FLGUI_TEST('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in FLGUI_TEST.M with the given input arguments.
  11. %
  12. % FLGUI_TEST('Property','Value',...) creates a new FLGUI_TEST or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before FlGui_test_OpeningFunction gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to FlGui_test_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 FlGui_test
  23. % Last Modified by GUIDE v2.5 13-Apr-2009 19:22:20
  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', @FlGui_test_OpeningFcn, ...
  29. 'gui_OutputFcn', @FlGui_test_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 FlGui_test is made visible.
  42. function FlGui_test_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 FlGui_test (see VARARGIN)
  48. % Choose default command line output for FlGui_test
  49. handles.output = handles;
  50. % Update handles structure
  51. guidata(hObject, handles);
  52. % load logo image
  53. logoPIC=imread('images/fslogo.jpg');
  54. axes(handles.axes1); image(logoPIC); axis off;
  55. set(get(handles.axes1,'Children'),'ButtonDownFcn','FlMiscGui');
  56. % UIWAIT makes FlGui_test wait for user response (see UIRESUME)
  57. % uiwait(handles.figure1);
  58. % --- Outputs from this function are returned to the command line.
  59. function varargout = FlGui_test_OutputFcn(hObject, eventdata, handles)
  60. % varargout cell array for returning output args (see VARARGOUT);
  61. % hObject handle to figure
  62. % eventdata reserved - to be defined in a future version of MATLAB
  63. % handles structure with handles and user data (see GUIDATA)
  64. % Get default command line output from handles structure
  65. varargout{1} = handles.output;
  66. % --- Executes on button press in pushbutton1.
  67. function pushbutton1_Callback(hObject, eventdata, handles)
  68. % hObject handle to pushbutton1 (see GCBO)
  69. % eventdata reserved - to be defined in a future version of MATLAB
  70. % handles structure with handles and user data (see GUIDATA)
  71. global FL
  72. % Shutdown Floodland timer which executes shutdown tasks
  73. try
  74. AccessRequest('release');
  75. stop(FL.t_main);
  76. catch
  77. exit;
  78. end % try/catch
  79. % --- Start app
  80. function pushbutton2_Callback(hObject, eventdata, handles)
  81. % hObject handle to pushbutton2 (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. global FL
  85. try
  86. % --- Run requested user app
  87. appList = get(handles.popupmenu1,'String');
  88. app = appList{get(handles.popupmenu1,'Value')};
  89. % Run as thread?
  90. runthread=0;
  91. % Are there any available/is this wanted?
  92. if ~exist(['testApps/',app],'dir') || exist(['testApps/',app,'/NOTHREAD'],'file')
  93. if get(handles.checkbox4,'Value')
  94. if isfield(FL,'threads') && isfield(FL.threads,'status') && ~isempty(FL.threads.status)
  95. if any(cellfun(@(x) strcmp(x,'running')))
  96. runthread=find(cellfun(@(x) strcmp(x,'running')),'first');
  97. else
  98. if ~strcmp(questdlg('No available non-busy threads, run in main thread?','No thread available',...
  99. 'Yes','No','No'),'Yes')
  100. return
  101. end
  102. end
  103. end
  104. end
  105. end
  106. if runthread
  107. stat = FlThreads('startApp',runthread,app);
  108. if stat{1}~=1
  109. if findstr(stat{2},'Can only run .fig or .m file in thread')
  110. runthread=0; % 3rd party apps run in own thread by definition
  111. else
  112. errordlg(stat{2},'Error starting app in thread')
  113. return
  114. end
  115. end
  116. end
  117. if ~runthread
  118. addpath(['testApps/',app]);
  119. if exist(['testApps/',app,'/',app,'.fig'],'file')
  120. evalc(['FL.Gui.(app)=',app,'(''UserData'',get(handles.figure1,''UserData''))']);
  121. elseif exist(['testApps/',app,'/',app,'.m'],'file')
  122. run(['testApps/',app,'/',app]);
  123. else
  124. if ~exist(['testApps/',app,'/',app],'file')
  125. errordlg('Application not found','Run user app error');
  126. return
  127. end
  128. evalc(['!testApps/',app,'/',app,'&']);
  129. end
  130. end
  131. catch
  132. errordlg(lasterr,'Error running requested application');
  133. bufferFlush;
  134. end
  135. % --- Executes on selection change in popupmenu1.
  136. function popupmenu1_Callback(hObject, eventdata, handles)
  137. % hObject handle to popupmenu1 (see GCBO)
  138. % eventdata reserved - to be defined in a future version of MATLAB
  139. % handles structure with handles and user data (see GUIDATA)
  140. % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
  141. % contents{get(hObject,'Value')} returns selected item from popupmenu1
  142. % --- Executes during object creation, after setting all properties.
  143. function popupmenu1_CreateFcn(hObject, eventdata, handles)
  144. % hObject handle to popupmenu1 (see GCBO)
  145. % eventdata reserved - to be defined in a future version of MATLAB
  146. % handles empty - handles not created until after all CreateFcns called
  147. % Hint: popupmenu controls usually have a white background on Windows.
  148. % See ISPC and COMPUTER.
  149. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  150. set(hObject,'BackgroundColor','white');
  151. end
  152. % --- FL server
  153. function pushbutton3_Callback(hObject, eventdata, handles)
  154. % hObject handle to pushbutton3 (see GCBO)
  155. % eventdata reserved - to be defined in a future version of MATLAB
  156. % handles structure with handles and user data (see GUIDATA)
  157. global FL
  158. % Start/Stop command handler
  159. if isequal(get(hObject,'BackgroundColor'),[1 0 0])
  160. % Start command handler
  161. if ~isfield(FL,'t_commandHandler') || ~isequal(FL.t_commandHandler.running,'on')
  162. ServerCommandHandler('init');
  163. FL.t_commandHandler=timer('StartDelay',1,'Period',FL.Period_commandHandler,...
  164. 'ExecutionMode','FixedRate','BusyMode','drop');
  165. FL.t_commandHandler.TimerFcn = 'ServerCommandHandler(''run'',''fl'')';
  166. FL.t_commandHandler.StopFcn = 'ServerCommandHandler(''stop'',''fl'')';
  167. start(FL.t_commandHandler);
  168. end % if command handler timer running
  169. % Initialise Floodland Server Socket
  170. sockrw('init-flserv');
  171. % indicate server running
  172. set(hObject,'BackgroundColor','Green');
  173. else
  174. if isfield(FL,'t_commandHandler') && isequal(FL.t_commandHandler.running,'on')
  175. stop(FL.t_commandHandler);
  176. end % if running, stop command handler
  177. % Stop connection timer if running
  178. if isfield(FL.Server,'t_connect') && isequal(FL.Server.t_connect.Running,'on')
  179. stop(FL.Server.t_connect);
  180. end % if t_connect timer running, stop
  181. clear ServerConnect
  182. set(hObject,'BackgroundColor','Red');
  183. % Send disconnect messages to any connected clients and delete
  184. disp('closing server connections...')
  185. srvs={'Server'};
  186. ssrvs={'fl'};
  187. socks={'socket' 'servSocket'};
  188. for isrv=1:length(srvs)
  189. if isfield(FL,srvs{isrv})
  190. users=fieldnames(FL.(srvs{isrv}));
  191. for iuser=1:length(users)
  192. if strcmp(users{iuser}(1:4),'user')
  193. for isock=1:length(socks)
  194. if isfield(FL.(srvs{isrv}).(users{iuser}),socks{isock}) && ...
  195. ~FL.(srvs{isrv}).(users{iuser}).(socks{isock}).isClosed
  196. try
  197. % Send disconnect message and close socket
  198. sockrw('set_user',ssrvs{isrv},users{iuser,1});
  199. sockrw('writechar',ssrvs{isrv},'disconnect');
  200. pause(1)
  201. FL.(srvs{isrv}).(users{iuser}).socket.close;
  202. FL.(srvs{isrv})=rmfield(FL.(srvs{isrv}),users{iuser});
  203. catch
  204. FL.(srvs{isrv})=rmfield(FL.(srvs{isrv}),users{iuser});
  205. continue
  206. end % try/catch
  207. end % if ~closed
  208. end % for isock
  209. end % if user field
  210. end % for iuser
  211. end % if srv field exists
  212. end % for isrv
  213. end % if button red
  214. % --- Executes on button press in checkbox1.
  215. function checkbox1_Callback(hObject, eventdata, handles)
  216. % hObject handle to checkbox1 (see GCBO)
  217. % eventdata reserved - to be defined in a future version of MATLAB
  218. % handles structure with handles and user data (see GUIDATA)
  219. % Hint: get(hObject,'Value') returns toggle state of checkbox1
  220. % --- Executes on selection change in popupmenu2.
  221. function popupmenu2_Callback(hObject, eventdata, handles)
  222. % hObject handle to popupmenu2 (see GCBO)
  223. % eventdata reserved - to be defined in a future version of MATLAB
  224. % handles structure with handles and user data (see GUIDATA)
  225. % Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
  226. % contents{get(hObject,'Value')} returns selected item from popupmenu2
  227. % --- Executes during object creation, after setting all properties.
  228. function popupmenu2_CreateFcn(hObject, eventdata, handles)
  229. % hObject handle to popupmenu2 (see GCBO)
  230. % eventdata reserved - to be defined in a future version of MATLAB
  231. % handles empty - handles not created until after all CreateFcns called
  232. % Hint: popupmenu controls usually have a white background on Windows.
  233. % See ISPC and COMPUTER.
  234. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  235. set(hObject,'BackgroundColor','white');
  236. end
  237. % --- Executes on button press in pushbutton4.
  238. function pushbutton4_Callback(hObject, eventdata, handles)
  239. % hObject handle to pushbutton4 (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. persistent lastTime
  243. % Slow down rate at which can click update button, otherwise crashes
  244. if ~get(handles.checkbox1,'Value') && (isempty(lastTime) || (toc-lastTime)>3)
  245. lastTime=toc;
  246. FlHwUpdate;
  247. end % update only if not already auto-updating
  248. % --- Executes on button press in checkbox2.
  249. function checkbox2_Callback(hObject, eventdata, handles)
  250. % hObject handle to checkbox2 (see GCBO)
  251. % eventdata reserved - to be defined in a future version of MATLAB
  252. % handles structure with handles and user data (see GUIDATA)
  253. % Hint: get(hObject,'Value') returns toggle state of checkbox2
  254. % --- Executes on button press in pushbutton5.
  255. function pushbutton5_Callback(hObject, eventdata, handles)
  256. % hObject handle to pushbutton5 (see GCBO)
  257. % eventdata reserved - to be defined in a future version of MATLAB
  258. % handles structure with handles and user data (see GUIDATA)
  259. if isequal(questdlg('Clear all PV access requests?'),'Yes')
  260. AccessRequest('release');
  261. end % if sure
  262. % --- Executes when user attempts to close figure1.
  263. function figure1_CloseRequestFcn(hObject, eventdata, handles)
  264. % hObject handle to figure1 (see GCBO)
  265. % eventdata reserved - to be defined in a future version of MATLAB
  266. % handles structure with handles and user data (see GUIDATA)
  267. % Hint: delete(hObject) closes the figure
  268. % Shutdown Floodland timer which executes shutdown tasks
  269. global FL
  270. try
  271. AccessRequest('release');
  272. stop(FL.t_main);
  273. catch
  274. exit;
  275. end % try/catch
  276. % --- Executes on button press in pushbutton6.
  277. function pushbutton6_Callback(hObject, eventdata, handles)
  278. % hObject handle to pushbutton6 (see GCBO)
  279. % eventdata reserved - to be defined in a future version of MATLAB
  280. % handles structure with handles and user data (see GUIDATA)
  281. global FL
  282. FL.Gui.BeamlineViewer = BeamlineViewer;
  283. % --- Executes on mouse press over axes background.
  284. function axes1_ButtonDownFcn(hObject, eventdata, handles)
  285. % hObject handle to axes1 (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. msgbox('Do not click here again...')
  289. % --- Safely delete an open figure/gui
  290. function pushbutton7_Callback(hObject, eventdata, handles)
  291. % hObject handle to pushbutton7 (see GCBO)
  292. % eventdata reserved - to be defined in a future version of MATLAB
  293. % handles structure with handles and user data (see GUIDATA)
  294. % --- Thread Control
  295. function pushbutton8_Callback(hObject, eventdata, handles)
  296. % hObject handle to pushbutton8 (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. FL.Gui.threadControl=threadControl;
  301. % --- Executes on button press in checkbox4.
  302. function checkbox4_Callback(hObject, eventdata, handles)
  303. % hObject handle to checkbox4 (see GCBO)
  304. % eventdata reserved - to be defined in a future version of MATLAB
  305. % handles structure with handles and user data (see GUIDATA)
  306. % Hint: get(hObject,'Value') returns toggle state of checkbox4
  307. % --- Executes on button press in pushbutton9.
  308. function pushbutton9_Callback(hObject, eventdata, handles)
  309. % hObject handle to pushbutton9 (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. resp=questdlg('Warning- will potentially interfere with any running client applications, continue?','Flush Comms Buffers?','Yes','No','No');
  313. if strcmp(resp,'Yes')
  314. stat=bufferFlush;
  315. if stat{1}~=1
  316. errordlg(stat{2},'Buffer Flush Error')
  317. else
  318. beep
  319. end
  320. end
  321. % --- Launch BPM tool
  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. global FL
  327. FL.Gui.FlBpmTool=FlBpmTool;