function varargout = transitionpicker(varargin)
% TRANSITIONPICKER MATLAB code for transitionpicker.fig
%      TRANSITIONPICKER, by itself, creates a new TRANSITIONPICKER or raises the existing
%      singleton*.
%
%      H = TRANSITIONPICKER returns the handle to a new TRANSITIONPICKER or the handle to
%      the existing singleton*.
%
%      TRANSITIONPICKER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TRANSITIONPICKER.M with the given input arguments.
%
%      TRANSITIONPICKER('Property','Value',...) creates a new TRANSITIONPICKER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before transitionpicker_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to transitionpicker_OpeningFcn via varargin.
%
%      *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 transitionpicker

% Last Modified by GUIDE v2.5 11-Dec-2013 17:00:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @transitionpicker_OpeningFcn, ...
                   'gui_OutputFcn',  @transitionpicker_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(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 transitionpicker is made visible.
function transitionpicker_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 transitionpicker (see VARARGIN)

% Choose default command line output for transitionpicker
handles.output = hObject;
handles.abort = 1;

varargin = varargin{1};
handles.transitionstotake = varargin{1};
handles.sets = varargin{2};

handles.results = varargin{3};
handles.omegas = varargin{4};
handles.time = varargin{5};
handles.iteration = varargin{6};
handles.qd = varargin{7};

transitionstrings = cell(length(handles.transitionstotake));
for i=1:length(handles.transitionstotake)
    transitionstrings{i} = sprintf('transition id: %d  (%d intersection sets)',handles.transitionstotake(i),sum(handles.sets(i,:) ~= 0));
end;
set(handles.transitionlist,'String',transitionstrings);

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes transitionpicker wait for user response (see UIRESUME)
uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = transitionpicker_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;
varargout{2} = ~handles.abort;
%contents = cellstr(get(hObject,'String'));

varargout{3} = (get(handles.transitionlist,'Value'));

varargout = {varargout};
delete(handles.figure1);

    


% --- Executes on selection change in transitionlist.
function transitionlist_Callback(hObject, eventdata, handles)
% hObject    handle to transitionlist (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns transitionlist contents as cell array
%        contents{get(hObject,'Value')} returns selected item from transitionlist


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


% --- Executes on button press in stopbutton.
function stopbutton_Callback(hObject, eventdata, handles)
% hObject    handle to stopbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.abort = 1;
guidata(hObject, handles);
uiresume(handles.figure1);

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.abort = 0;
guidata(hObject, handles);
uiresume(handles.figure1);

% --- Executes during object deletion, before destroying properties.
function figure1_DeleteFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


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


% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: delete(hObject) closes the figure
if isequal(get(hObject, 'waitstatus'), 'waiting')
    % The GUI is still in UIWAIT, us UIRESUME
    uiresume(hObject);
else
    % The GUI is no longer waiting, just close it
    delete(hObject);
end


% --- Executes on button press in store.
function store_Callback(hObject, eventdata, handles)
% hObject    handle to store (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
store_state(handles.results, handles.omegas,handles.time,handles.iteration,handles.sets, handles.transitionstotake, handles.qd);
