function varargout = automation(varargin)
% AUTOMATION M-file for automation.fig
%      AUTOMATION, by itself, creates a new AUTOMATION or raises the existing
%      singleton*.
%
%      H = AUTOMATION returns the handle to a new AUTOMATION or the handle to
%      the existing singleton*.
%
%      AUTOMATION('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named AUTOMATION in AUTOMATION.M with the given input arguments.
%
%      AUTOMATION('Property','Value',...) creates a new AUTOMATION or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before automation_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to automation_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% Code construction assisted by GUIDE
%
%    GENERAL
%
%      Omitted.
%
%    INPUT/S
%
%      -
%          
%           
%    OUTPUT/S
%
%      -
%
%    PENDING WORK
%
%      -
%
%    KNOWN BUG/S
%
%      -
%
%    COMMENT/S
%
%      -
%
%    RELATED FUNCTION/S
%
%      
%
%    ABOUT
%
%      -Created:     March 22nd, 2004
%      -Last update: 
%      -Revision:    0.0.1
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

% Edit the above text to modify the response to help_button register

% Last Modified by GUIDE v2.5 25-Mar-2004 04:20:47

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @automation_OpeningFcn, ...
    'gui_OutputFcn',  @automation_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 register is made visible.
function automation_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   command line arguments to register (see VARARGIN)

% Choose default command line output for register
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

if strcmp(get(hObject,'Visible'),'off')
    initialize_gui(hObject, handles);
end

% UIWAIT makes register pause for user response (see UIRESUME)
% uiwait(handles.Advanced_window);

% ==================================================================== %  

% --- Outputs from this function are returned to the command line.
function varargout = automation_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;

% ==================================================================== %  

function initialize_gui(fig_handle, handles)

set(handles.minimum_value, 'String', getappdata(0, 'minimum_value'));
set(handles.minimum_slider, 'Value', str2num(get(handles.minimum_value, 'String')));

set(handles.maximum_value, 'String', getappdata(0, 'maximum_value'));
set(handles.maximum_slider, 'Value', str2num(get(handles.maximum_value, 'String')));

set(handles.step_size, 'String', getappdata(0, 'step_size'));
set(handles.step_slider, 'Value', str2num(get(handles.step_size, 'String')));

set(handles.automation_type_parameter, 'String', getappdata(0, 'automation_type'));

background = imread('background.jpg');

axes(handles.background);
axis off;
imshow(background,[0,255]);

% ==================================================================== %  

% --- Executes on button press in ok_botton.
function ok_botton_Callback(hObject, eventdata, handles)
% hObject    handle to ok_botton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


setappdata(0, 'minimum_value', get(handles.minimum_value, 'String'));
setappdata(0, 'maximum_value', get(handles.maximum_value, 'String'));
setappdata(0, 'step_size', get(handles.step_size, 'String'));
setappdata(0, 'automation_type', get(handles.automation_type_parameter, 'String'));
close;

% ==================================================================== %  

% --- Executes on button press in cancel_button.
function cancel_button_Callback(hObject, eventdata, handles)
% hObject    handle to cancel_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

close;

% ==================================================================== %  

% --- Executes on button press in apply_button.
function apply_button_Callback(hObject, eventdata, handles)
% hObject    handle to apply_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

setappdata(0, 'minimum_value', get(handles.minimum_value, 'String'));
setappdata(0, 'maximum_value', get(handles.maximum_value, 'String'));
setappdata(0, 'step_size', get(handles.step_size, 'String'));
setappdata(0, 'automation_type', get(handles.automation_type_parameter, 'String'));

% ==================================================================== %  

% --- Executes during object creation, after setting all properties.
function step_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to step_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== %  

% --- Executes on slider movement.
function step_slider_Callback(hObject, eventdata, handles)
% hObject    handle to step_slider (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

set(handles.step_size, 'String', num2str(ceil(get(handles.step_slider, 'Value'))));

% ==================================================================== %  

% --- Executes during object creation, after setting all properties.
function maximum_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to maximum_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== %  

% --- Executes on slider movement.
function maximum_slider_Callback(hObject, eventdata, handles)
% hObject    handle to maximum_slider (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

set(handles.maximum_value, 'String', num2str(ceil(get(handles.maximum_slider, 'Value'))));

% ==================================================================== %  

% --- Executes during object creation, after setting all properties.
function automation_menu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to automation_menu (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.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== %  

% --- Executes on selection change in automation_menu.
function automation_menu_Callback(hObject, eventdata, handles)
% hObject    handle to automation_menu (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 automation_menu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from automation_menu


contents = get(hObject,'String');

if (strcmp(contents{get(hObject,'Value')},'Number of Knot-points')),
       set(handles.automation_type_parameter, 'String', 'Number of Knot-points');  
elseif (strcmp(contents{get(hObject,'Value')},'Number of Modes')),
       set(handles.automation_type_parameter, 'String', 'Number of Modes');  
elseif (strcmp(contents{get(hObject,'Value')},'Model Weight')),
       set(handles.automation_type_parameter, 'String', 'Model Weight'); 
elseif (strcmp(contents{get(hObject,'Value')},'Smoothing')),
       set(handles.automation_type_parameter, 'String', 'Smoothing'); 
elseif (strcmp(contents{get(hObject,'Value')},'Perturbation')),
       set(handles.automation_type_parameter, 'String', 'Perturbation');            
elseif (strcmp(contents{get(hObject,'Value')},'None')),
       set(handles.automation_type_parameter, 'String', 'None');       
else
    error('Wrong values passed from automation type menu. Internal error.');
end

% ==================================================================== %  

% --- Executes during object creation, after setting all properties.
function minimum_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to minimum_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== %  

% --- Executes on slider movement.
function minimum_slider_Callback(hObject, eventdata, handles)
% hObject    handle to minimum_slider (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider



set(handles.minimum_value, 'String', num2str(ceil(get(handles.minimum_slider, 'Value'))));
