%NACTENI GUI A TLACITEK

function varargout = MarkersGUI(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @MarkersGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @MarkersGUI_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

function MarkersGUI_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;

guidata(hObject, handles);

function varargout = MarkersGUI_OutputFcn(hObject, eventdata, handles) 

varargout{1} = handles.output;

function Bits_Callback(hObject, eventdata, handles)

function Bits_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function MarkersCount_Callback(hObject, eventdata, handles)

function MarkersCount_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function FileName_Callback(hObject, eventdata, handles)

function FileName_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function HammingDist_Callback(hObject, eventdata, handles)

function HammingDist_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

%SAMOTNY GENERATOR - POD TLACITKEM COMPUTE

function Compute_Callback(hObject, eventdata, handles)

%NACHYSTANI HODNOT, VYGENEROVANI CYKLICKYCH PERMUTACI S OPAKOVANIM

BIT = str2double(get(handles.Bits,'String'));                               %pocet bitu                                                            

CCOUNT = str2double(get(handles.MarkersCount,'String'));                    %pocet kalibracnich znacek
                                                      
h = waitbar(0/2,'Hledani cyklickych permutaci');                            %progressbar

CPERM = CyclicPerm(BIT);                                                    %generovani cykl. permutaci

%VYBER KNIHOVNY KODU KALIBRACNICH ZNACEK LIB

delete(h);
        
h = waitbar(1/2,'Vyber knihovny');                                          %progressbar

clear global LIB

global LIB;                                                                 %priprava globalni promenne - vysledna knihovna

[ LIB, Kmin ] = LibraryGenerator( CPERM,CCOUNT,BIT );                       %vygenerovani knihovny, Kmin nese informaci o minimalnim plneni kriterii

set(handles.HammingDist,'String',num2str(round(Kmin)));                     %informovani uzivatele o minimalnim splneni kriterii

ACODE = linspace(1,CCOUNT,CCOUNT);

LIB = horzcat (ACODE(:),LIB);                                               %vysledna podoba knihovny

delete(h);

%TALCITKO SAVE - ULOZENI KNIHOVNY

function Save_Callback(hObject, eventdata, handles)

global LIB

xlswrite(get(handles.FileName,'String'),LIB);                                %ulozeni knihovny na pokyn uzivatele
