function varargout = ctrlGUI(varargin)
% CTRLGUI M-file for ctrlGUI.fig
% CTRLGUI, by itself, creates a new CTRLGUI or raises the existing
% singleton*.
%
% H = CTRLGUI returns the handle to a new CTRLGUI or the handle to
% the existing singleton*.
%
% CTRLGUI('Property','Value',...) creates a new CTRLGUI using the
% given property value pairs. Unrecognized properties are passed via
% varargin to ctrlGUI_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% CTRLGUI('CALLBACK') and CTRLGUI('CALLBACK',hObject,...) call the
% local function named CALLBACK in CTRLGUI.M with the given input
% arguments.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help ctrlGUI
% Last Modified by GUIDE v2.5 07-Oct-2006 16:46:39
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ctrlGUI_OpeningFcn, ...
'gui_OutputFcn', @ctrlGUI_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before ctrlGUI is made visible.
function ctrlGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for ctrlGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ctrlGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% First, we shall copy all necessary data from the global 'g_ctmGUI' structure
global g_ctmGUI; % MUST (!) exist - the call to 'ctrlGUI' is initiated from 'ctmGUI'
global g_ctrlGUI;
g_ctrlGUI.configFile = g_ctmGUI.configFile;
g_ctrlGUI.cellData = g_ctmGUI.cellData;
g_ctrlGUI.pmData = g_ctmGUI.pmData;
g_ctrlGUI.freeway = g_ctmGUI.freeway;
g_ctrlGUI.cellIndex = 1;
g_ctrlGUI.mlcpIndex = 3;
g_ctrlGUI.qcpIndex = 3;
g_ctrlGUI.mlController = g_ctrlGUI.cellData(1).ORmlcontroller;
g_ctrlGUI.qController = g_ctrlGUI.cellData(1).ORqcontroller;
xmin = g_ctrlGUI.cellData(1).PMstart;
xmax = g_ctrlGUI.cellData(end).PMend;
if xmin <= xmax
g_ctrlGUI.xLims = [xmin xmax];
else
g_ctrlGUI.xLims = [xmax xmin];
end
g_ctrlGUI.OK = 0;
NC = size(g_ctrlGUI.cellData, 2);
orlst = get_ramp_lists(g_ctrlGUI.cellData);
orlst = orlst(2:(NC+1), :); % remove in- and out- flow entries
set(handles.cellList, 'String', orlst);
set(handles.header, 'String', [g_ctrlGUI.freeway ' on-ramp control']);
axes(handles.direction);
if g_ctrlGUI.cellData(1).PMstart <= g_ctrlGUI.cellData(1).PMend
image(imread('lr.jpg'));
else
image(imread('rl.jpg'));
end
axis off;
axes(handles.freeway);
plotbar(g_ctrlGUI.pmData, 0.5*ones(1, NC), 'w');
hold on;
plotbar([g_ctrlGUI.pmData(1) g_ctrlGUI.pmData(2)], 0.5, 'k');
plot(g_ctrlGUI.pmData(1), 0.75, 'bv', 'MarkerFaceColor', 'b');
axis([g_ctrlGUI.xLims 0 1]);
xlabel('Post mile');
set(handles.freeway, 'YTick', []);
hold off;
load ormlclist;
set(handles.mlctrlList, 'String', mlclist);
load orqclist;
set(handles.qctrlList, 'String', qclist);
if isempty(g_ctrlGUI.cellData(1).ORname)
set(handles.mlctrlList, 'Value', 1);
set(handles.mlctrlList, 'Enable', 'off');
set(handles.qctrlList, 'Value', 1);
set(handles.qctrlList, 'Enable', 'off');
else
set(handles.mlctrlList, 'Enable', 'on');
set(handles.qctrlList, 'Enable', 'on');
if isempty(g_ctrlGUI.mlController)
set(handles.mlctrlList, 'Value', 1);
else
set(handles.mlctrlList, 'Value', g_ctrlGUI.mlController.id);
end
if isempty(g_ctrlGUI.qController)
set(handles.qctrlList, 'Value', 1);
else
set(handles.qctrlList, 'Value', g_ctrlGUI.qController.id);
end
end
set(handles.applyCButton, 'Enable', 'off');
set(handles.applyQCButton, 'Enable', 'off');
ormlc_menu_action(handles);
orqc_menu_action(handles);
return;
% --- Outputs from this function are returned to the command line.
function varargout = ctrlGUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
return;
% --- Executes during object creation, after setting all properties.
function mlctrlList_CreateFcn(hObject, eventdata, handles)
% hObject handle to mlctrlList (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
% --- Executes on selection change in mlctrlList.
function mlctrlList_Callback(hObject, eventdata, handles)
% hObject handle to mlctrlList (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns mlctrlList contents as cell array
% contents{get(hObject,'Value')} returns selected item from mlctrlList
global g_ctrlGUI;
set(handles.applyCButton, 'Enable', 'on');
idx = get(hObject, 'Value');
nms = get(hObject, 'String');
g_ctrlGUI.mlController = get_mlc_default(deblank(nms(idx, :)));
g_ctrlGUI.mlcpIndex = 3;
ormlc_menu_action(handles);
return;
% --- Executes during object creation, after setting all properties.
function mlcpValue_CreateFcn(hObject, eventdata, handles)
% hObject handle to mlcpValue (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
function mlcpValue_Callback(hObject, eventdata, handles)
% hObject handle to mlcpValue (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of mlcpValue as text
% str2double(get(hObject,'String')) returns contents of mlcpValue as a double
global g_ctrlGUI;
buf = get(hObject, 'String');
N = size(buf, 1); % number of lines
str = [];
for i = 1:N
str = [str buf{i, 1}];
end
fns = fieldnames(g_ctrlGUI.mlController);
g_ctrlGUI.mlController = setfield(g_ctrlGUI.mlController, fns{g_ctrlGUI.mlcpIndex, 1}, eval(str));
set(handles.applyCButton, 'Enable', 'on');
return;
% --- Executes on button press in prevMLCP.
function prevMLCP_Callback(hObject, eventdata, handles)
% hObject handle to prevMLCP (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_ctrlGUI;
g_ctrlGUI.mlcpIndex = g_ctrlGUI.mlcpIndex - 1;
ormlc_menu_action(handles);
return;
% --- Executes on button press in nextMLCP.
function nextMLCP_Callback(hObject, eventdata, handles)
% hObject handle to nextMLCP (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_ctrlGUI;
g_ctrlGUI.mlcpIndex = g_ctrlGUI.mlcpIndex + 1;
ormlc_menu_action(handles);
return;
% --- Executes on button press in applyCButton.
function applyCButton_Callback(hObject, eventdata, handles)
% hObject handle to applyCButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_ctrlGUI;
g_ctrlGUI.cellData(g_ctrlGUI.cellIndex).ORmlcontroller = g_ctrlGUI.mlController;
set(handles.applyCButton, 'Enable', 'off');
return;
% --- Executes during object creation, after setting all properties.
function qctrlList_CreateFcn(hObject, eventdata, handles)
% hObject handle to qctrlList (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
% --- Executes on selection change in qctrlList.
function qctrlList_Callback(hObject, eventdata, handles)
% hObject handle to qctrlList (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns qctrlList contents as cell array
% contents{get(hObject,'Value')} returns selected item from qctrlList
global g_ctrlGUI;
set(handles.applyQCButton, 'Enable', 'on');
idx = get(hObject, 'Value');
nms = get(hObject, 'String');
g_ctrlGUI.qController = get_qc_default(deblank(nms(idx, :)));
g_ctrlGUI.qcpIndex = 3;
orqc_menu_action(handles);
return;
% --- Executes during object creation, after setting all properties.
function qcpValue_CreateFcn(hObject, eventdata, handles)
% hObject handle to qcpValue (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
function qcpValue_Callback(hObject, eventdata, handles)
% hObject handle to qcpValue (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of qcpValue as text
% str2double(get(hObject,'String')) returns contents of qcpValue as a double
global g_ctrlGUI;
buf = get(hObject, 'String');
N = size(buf, 1); % number of lines
str = [];
for i = 1:N
str = [str buf{i, 1}];
end
fns = fieldnames(g_ctrlGUI.qController);
g_ctrlGUI.qController = setfield(g_ctrlGUI.qController, fns{g_ctrlGUI.qcpIndex, 1}, eval(str));
set(handles.applyQCButton, 'Enable', 'on');
return;
% --- Executes on button press in prevQCP.
function prevQCP_Callback(hObject, eventdata, handles)
% hObject handle to prevQCP (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_ctrlGUI;
g_ctrlGUI.qcpIndex = g_ctrlGUI.qcpIndex - 1;
orqc_menu_action(handles);
return;
% --- Executes on button press in nextQCP.
function nextQCP_Callback(hObject, eventdata, handles)
% hObject handle to nextQCP (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_ctrlGUI;
g_ctrlGUI.qcpIndex = g_ctrlGUI.qcpIndex + 1;
orqc_menu_action(handles);
return;
% --- Executes on button press in applyQCButton.
function applyQCButton_Callback(hObject, eventdata, handles)
% hObject handle to applyQCButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_ctrlGUI;
g_ctrlGUI.cellData(g_ctrlGUI.cellIndex).ORqcontroller = g_ctrlGUI.qController;
set(handles.applyQCButton, 'Enable', 'off');
return;
% --- Executes during object creation, after setting all properties.
function cellList_CreateFcn(hObject, eventdata, handles)
% hObject handle to cellList (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
% --- Executes on selection change in cellList.
function cellList_Callback(hObject, eventdata, handles)
% hObject handle to cellList (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns cellList contents as cell array
% contents{get(hObject,'Value')} returns selected item from cellList
global g_ctrlGUI;
axes(handles.freeway);
plotbar(g_ctrlGUI.pmData, 0.5*ones(1, size(g_ctrlGUI.cellData, 2)), 'w');
hold on;
idx = get(hObject, 'Value');
plotbar([g_ctrlGUI.pmData(idx) g_ctrlGUI.pmData(idx+1)], 0.5, 'k');
plot(g_ctrlGUI.pmData(idx), 0.75, 'bv', 'MarkerFaceColor', 'b');
axis([g_ctrlGUI.xLims 0 1]);
xlabel('Post mile');
set(handles.freeway, 'YTick', []);
hold off;
set(handles.applyCButton, 'Enable', 'off');
set(handles.applyQCButton, 'Enable', 'off');
g_ctrlGUI.mlcpIndex = 3;
g_ctrlGUI.qcpIndex = 3;
g_ctrlGUI.mlController = g_ctrlGUI.cellData(idx).ORmlcontroller;
g_ctrlGUI.qController = g_ctrlGUI.cellData(idx).ORqcontroller;
if isempty(g_ctrlGUI.cellData(idx).ORname)
set(handles.mlctrlList, 'Value', 1);
set(handles.mlctrlList, 'Enable', 'off');
set(handles.qctrlList, 'Value', 1);
set(handles.qctrlList, 'Enable', 'off');
else
set(handles.mlctrlList, 'Enable', 'on');
set(handles.qctrlList, 'Enable', 'on');
if isempty(g_ctrlGUI.mlController)
set(handles.mlctrlList, 'Value', 1);
else
set(handles.mlctrlList, 'Value', g_ctrlGUI.mlController.id);
end
if isempty(g_ctrlGUI.qController)
set(handles.qctrlList, 'Value', 1);
else
set(handles.qctrlList, 'Value', g_ctrlGUI.qController.id);
end
end
ormlc_menu_action(handles);
orqc_menu_action(handles);
g_ctrlGUI.cellIndex = idx;
return;
% --- Executes on button press in saveButton.
function saveButton_Callback(hObject, eventdata, handles)
% hObject handle to saveButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_ctrlGUI;
save_controllers(g_ctrlGUI.cellData, g_ctrlGUI.configFile);
return;
% --- Executes on button press in cancelButton.
function cancelButton_Callback(hObject, eventdata, handles)
% hObject handle to cancelButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ctrlGUIclose;
return;
% --- Executes on button press in okButton.
function okButton_Callback(hObject, eventdata, handles)
% hObject handle to okButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_ctrlGUI;
g_ctrlGUI.OK = 1;
ctrlGUIclose;
return;
% --- Executes on button press in applytoallButton.
function applytoallButton_Callback(hObject, eventdata, handles)
% hObject handle to applytoallButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_ctrlGUI;
N = size(g_ctrlGUI.cellData, 2);
for i = 1:N
if ~isempty(g_ctrlGUI.cellData(i).ORname)
g_ctrlGUI.cellData(i).ORmlcontroller = g_ctrlGUI.mlController;
end
end
set(handles.applyCButton, 'Enable', 'off');
return;
% --- Executes on button press in applytoall2Button.
function applytoall2Button_Callback(hObject, eventdata, handles)
% hObject handle to applytoall2Button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global g_ctrlGUI;
N = size(g_ctrlGUI.cellData, 2);
for i = 1:N
if ~isempty(g_ctrlGUI.cellData(i).ORname)
g_ctrlGUI.cellData(i).ORqcontroller = g_ctrlGUI.qController;
end
end
set(handles.applyQCButton, 'Enable', 'off');
return;