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

% Last Modified by GUIDE v2.5 15-May-2012 16:36:53

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @BCH_gui_OpeningFcn, ...
                   'gui_OutputFcn',  @BCH_gui_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 BCH_gui is made visible.
function BCH_gui_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 BCH_gui (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);


% UIWAIT makes BCH_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
set(handles.dekoduj,'Enable','off');
set(handles.nahodne_chyby,'Enable','off');
set(handles.diagram,'Enable','off');
% --- Outputs from this function are returned to the command line.
function varargout = BCH_gui_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;

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


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



function vstup_Callback(hObject, eventdata, handles)
% hObject    handle to vstup (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 vstup as text
%        str2double(get(hObject,'String')) returns contents of vstup as a double


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



function kodove_slovo_Callback(hObject, eventdata, handles)
% hObject    handle to text15 (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 text15 as text
%        str2double(get(hObject,'String')) returns contents of text15 as a double


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


% --- Executes on button press in nahodny_vstup.
function nahodny_vstup_Callback(hObject, eventdata, handles)
% hObject    handle to nahodny_vstup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
k = 0;
switch get(handles.vyber_kod,'Value')   
    case 2
        n = 7; k = 3; m = 3; 
        bch=0;
    case 3
        n = 15; k = 11; m = 4; 
        bch=0;
    case 4
        n= 7; k= 4; m=3;pp=11; t=1;
        bch=1;
    case 5
        n= 15; k= 7; m=4;pp=19; t=2;
        bch=1;
    otherwise
end
if k == 0
    msgbox ('Nejprve vyberte kód','Help','help');
else
    if bch==1
       vstupnislovo = round(rand(1,k));
        vstupnislovo = num2str(vstupnislovo);
        set(handles.vstup,'String',vstupnislovo);
        
    else
vstupnislovo = round(rand(1,k)*((2^m)-1));
vstupnislovo = num2str(vstupnislovo);
set(handles.vstup,'String',vstupnislovo);
    end
end

% --- Executes on button press in Zakoduj.
function Zakoduj_Callback(hObject, eventdata, handles)
% hObject    handle to Zakoduj (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%global krok;
global n;
global k;
global m;
global t;
global pp;
global vstupnislovo;
global odeslaneslovo;
global slovo;
global bch;
clc;
 vstupnislovo = str2num(get(handles.vstup,'String'));

if isempty(vstupnislovo)
    msgbox ('Musíte zadat vstupní slovo','Help','help');
else
switch get(handles.vyber_kod,'Value')   
    case 2
        n = 7; k = 3; m = 3; pp=13; t=2;
        bch=0;
    case 3
        n = 15; k = 11; m = 4; pp = 19; t=2;
        bch=0;
    case 4
         pomk = find(vstupnislovo > 1);
         if isempty(pomk)
        n= 7; k= 4; m=3;pp=11; t=1;
        msg = gf(vstupnislovo);
        [slovo, gpoly, parita, paritanul] = bchenc(msg,n,k);
        bch=1;
        
         else
             msgbox ('Špatně zadáné vstupní slovo, musí být binární','Help','help');
             bch=2;
         end
    case 5
        n= 15; k= 7; m=4;pp=19; t=2;
        msg = gf(vstupnislovo);
        [slovo, gpoly, parita, paritanul] = bchenc(msg,n,k);
        bch=1;
        
    otherwise
end

    if length(vstupnislovo) ~= k
        msgbox ('Špatně zadáné vstupní slovo, musí být délky k symbolů','Help','help');
    else
        switch bch
            case 0
                msg = gf(vstupnislovo, m, pp);
                [slovo, gpoly, parita, paritanul]= rsencpz(msg, n, k);
                parita=double(parita.x);
                control = 1;
                chyba = 0;
                odeslaneslovo = slovo;
                slovo = double(slovo.x);
                slovo = num2str(slovo);
                parita = num2str(parita);
                paritanul=double(paritanul.x);
                paritanul = num2str(paritanul);
                gpoly = double(gpoly.x);
                gpoly = num2str(gpoly);
                set(handles.kodove_slovo,'String',slovo);
                set(handles.genpoly_z,'String',gpoly);
                set(handles.zbytek_deleni,'String',parita);
                set(handles.vstupnul,'String',paritanul);
                msgbox ('Zakódování proběhlo úspěšně','Help','help');
                set(handles.dekoduj,'Enable','on');
                set(handles.nahodne_chyby,'Enable','on');
            case 1       
                odeslaneslovo = slovo;
                slovo = double(slovo.x);
                slovo = num2str(slovo);
                parita = num2str(parita);
                paritanul=double(paritanul.x);
                paritanul = num2str(paritanul);
                gpoly = double(gpoly.x);
                gpoly = num2str(gpoly);
                set(handles.kodove_slovo,'String',slovo);
                set(handles.genpoly_z,'String',gpoly);
                set(handles.zbytek_deleni,'String',parita);
                set(handles.vstupnul,'String',paritanul);
                msgbox ('Zakódování proběhlo úspěšně','Help','help');
                set(handles.dekoduj,'Enable','on');
                set(handles.nahodne_chyby,'Enable','on');
            otherwise
        end
 end
 end 


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


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



function vstup_chyb_Callback(hObject, eventdata, handles)
% hObject    handle to vstup_chyb (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 vstup_chyb as text
%        str2double(get(hObject,'String')) returns contents of vstup_chyb as a double


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


% --- Executes on button press in nahodne_chyby.
function nahodne_chyby_Callback(hObject, eventdata, handles)
% hObject    handle to nahodne_chyby (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global n;
global k;
global m;
global t;
global pp;
global bch;
pocetchyb=str2num(get(handles.pocet_chyb,'String'));
if isempty(pocetchyb)
    msgbox ('Zadejte nejprve počet chyb','Help','help');
else
chyby = zeros(1, n);
poz=zeros(1,pocetchyb);

if pocetchyb ~= 0
   poz = randi(n,pocetchyb);
    for j = 1:pocetchyb
            if poz(j) ~= 0
                if bch == 1
                chyby(poz(j)) = 1;
                else
                 chyby(poz(j)) = randi(((2^m)-1));
                end
            end
    end
end
chyby = num2str(chyby);
set(handles.vstup_chyb,'String',chyby);
end


function opraveno_Callback(hObject, eventdata, handles)
% hObject    handle to opraveno (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 opraveno as text
%        str2double(get(hObject,'String')) returns contents of opraveno as a double


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


% --- Executes on button press in dekoduj.
function dekoduj_Callback(hObject, eventdata, handles)
% hObject    handle to dekoduj (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global n;
global k;
global m;
global pp;
global odeslaneslovo;
global chyby;
global slovo;
global zobrazdiagram;

 chyby = str2num(get(handles.vstup_chyb,'String'));
if isempty(chyby)
    msgbox ('Musíte zadat vektor chyb','Help','help');
else

    if length(chyby) ~= n
        msgbox ('Špatně zadáný chybový vektor, musí mít délku n symbolů','Help','help');
    else

 switch get(handles.vyber_metodu,'Value')   
    case 1 
                msgbox ('Vyberte dekódovací metodu','Help','help');  
                set(handles.diagram,'Enable','off');
                zobrazdiagram=0;
                control = 0;
    case 2
        if get(handles.vyber_kod,'Value')<4
                [prijate_chybne, opraveno, hodnotachyb, pozice, polynom_chyb, syndromy, chyba] = pgzdek(n, k, m, pp, odeslaneslovo, chyby);
                set(handles.diagram,'Enable','on');
                zobrazdiagram=1;
                control = 1;
        else
                msgbox ('Vybrali jste špatnou dekódovací metodu pro BCH kódy vyberte např BCH PGZ','Warning','warn'); 
                control = 0;
        end
       
    case 3
        if get(handles.vyber_kod,'Value')<4
                [prijate_chybne, opraveno, hodnotachyb, pozice, polynom_chyb, syndromy, chyba] = bmdec(n, k, m, pp, odeslaneslovo, chyby);
                set(handles.diagram,'Enable','on');
                zobrazdiagram=0;
                control = 1; 
        else
                msgbox ('Vybrali jste špatnou dekódovací metodu pro BCH kódy vyberte např BCH PGZ','Warning','warn'); 
                control = 0;
         end
    case 4
                msgbox ('Pro binární kódy vyberte metody pod touto volbou','Warning','warn');
                control = 0;
    case 5
         if get(handles.vyber_kod,'Value')>3
                [prijate_chybne, opraveno, syndromy, pozice,hodnotachyb,polynom_chyb,chyba]= bchpgzdek(n, k, m, pp, odeslaneslovo, chyby);
                set(handles.diagram,'Enable','on');
                zobrazdiagram=1;
                control =1;
         else
                msgbox ('Vybrali jste špatnou dekódovací metodu pro RS kódy vyberte např RS PGZ algoritmus','Warning','warn'); 
                control = 0;
         end
     case 6 
         if get(handles.vyber_kod,'Value')>3
                [prijate_chybne, opraveno, syndromy,pozice,hodnotachyb,polynom_chyb,chyba]= bchbmdek(n, k, m, pp, odeslaneslovo, chyby);
                set(handles.diagram,'Enable','on');
                zobrazdiagram=0;
                control =1;
         else
                msgbox ('Vybrali jste špatnou dekódovací metodu pro RS kódy vyberte např RS PGZ algoritmus','Warning','warn'); 
                control = 0;
         end
     case 7
         if get(handles.vyber_kod,'Value')>3
                [prijate_chybne, opraveno, syndromy,pozice,hodnotachyb,polynom_chyb,chyba] = bcheuklidek(n, k, m, pp, odeslaneslovo, chyby);
                set(handles.diagram,'Enable','off');
                zobrazdiagram=0;
                control = 1;
         else
                msgbox ('Vybrali jste špatnou dekódovací metodu pro RS kódy vyberte např RS PGZ algoritmus','Warning','warn'); 
                control = 0;
         end
    otherwise
 end
  


 if control == 1
 dekodovano = num2str(opraveno(1:k));
 set(handles.opraveno,'String',dekodovano);
 opraveno = num2str(opraveno);
 set(handles.opravene_slovo,'String',opraveno);
 prijate_chybne = num2str(prijate_chybne);
 set(handles.kodove_slovo_chyba,'String',prijate_chybne);
 syndromy = num2str(syndromy); 
 set(handles.syndromyc,'String',syndromy);
  pozice = num2str(pozice);
  set(handles.pozice_chyb,'String',pozice);
 hodnotachyb = num2str(hodnotachyb);
 set(handles.hod_chyb,'String',hodnotachyb);
 polynom_chyb = num2str(polynom_chyb); 
 set(handles.chyb_poly,'String',polynom_chyb);
 
 
 if chyba == 0
     msgbox ('Dekódování uspěšné','Help','help');
 else
     msgbox ('Vyskytlo se více chyb, dekódování selhalo','Error','error');

 end
 end
 end
 end



function kodove_slovo_chyby_Callback(hObject, eventdata, handles)
% hObject    handle to kodove_slovo_chyba (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 kodove_slovo_chyba as text
%        str2double(get(hObject,'String')) returns contents of kodove_slovo_chyba as a double


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


% --- Executes on button press in help_vyber.
function help_vyber_Callback(hObject, eventdata, handles)
% hObject    handle to help_vyber (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 msgbox ('Vyberte kód, tvaru RS(n,k,t) nebo BCH(n,k,t), kde n je počet výstupních symbolů, k počet vstupních symbolů a t korekční schopnost kódu','Help','help');


% --- Executes on button press in help_vstup.
function help_vstup_Callback(hObject, eventdata, handles)
% hObject    handle to help_vstup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Pro RS kódy je vstup zadáván ve tvaru 1 3 4, kdy jednotlivé symboly jsou z GF a jejich binární hodnota převedena do desítkové soustavy, pro binární BCH kódy je vstup přímo v binární formě, vektor musí být délky k','Help','help');


% --- Executes on button press in help_vstupn.
function help_vstupn_Callback(hObject, eventdata, handles)
% hObject    handle to help_vstupn (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Generuje náhodně vstupní slovo','Help','help');


% --- Executes on button press in help_metoda.
function help_metoda_Callback(hObject, eventdata, handles)
% hObject    handle to help_metoda (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Vyberte dekodovací metodu pro ukázku dekódování','Help','help');



function vstupni_slovo_binar_Callback(hObject, eventdata, handles)
% hObject    handle to vstupni_slovo_binar (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 vstupni_slovo_binar as text
%        str2double(get(hObject,'String')) returns contents of vstupni_slovo_binar as a double


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



function vstupnul_Callback(hObject, eventdata, handles)
% hObject    handle to vstupnul (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 vstupnul as text
%        str2double(get(hObject,'String')) returns contents of vstupnul as a double


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



function zbytek_deleni_Callback(hObject, eventdata, handles)
% hObject    handle to zbytek_deleni (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 zbytek_deleni as text
%        str2double(get(hObject,'String')) returns contents of zbytek_deleni as a double


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



function genpoly_z_Callback(hObject, eventdata, handles)
% hObject    handle to genpoly_z (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 genpoly_z as text
%        str2double(get(hObject,'String')) returns contents of genpoly_z as a double


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


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


% --- Executes on button press in help_slovo_roz.
function help_slovo_roz_Callback(hObject, eventdata, handles)
% hObject    handle to help_slovo_roz (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Rozšířené vstupní slovo o stupeň generujícího polynomu','Help','help');


% --- Executes on button press in help_zbytek.
function help_zbytek_Callback(hObject, eventdata, handles)
% hObject    handle to help_zbytek (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Zbytek po dělení rošířeného vstupního slova s generujícím polynomem','Help','help');


% --- Executes on button press in help_chybyn.
function help_chybyn_Callback(hObject, eventdata, handles)
% hObject    handle to help_chybyn (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Generuje náhodně vektor chyb','Help','help');


% --- Executes on button press in help_chybv.
function help_chybv_Callback(hObject, eventdata, handles)
% hObject    handle to help_chybv (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Pro RS kódy je vektor chyb zadáván ve tvaru 1 3 4, kdy jednotlivé symboly jsou z GF a jejich binární hodnota převedena do desítkové soustavy, pro binární BCH kódy jsou chyby přímo v binární formě, vektor musí být délky n','Help','help');



function hod_chyb_Callback(hObject, eventdata, handles)
% hObject    handle to hod_chyb (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 hod_chyb as text
%        str2double(get(hObject,'String')) returns contents of hod_chyb as a double


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



function pozice_chyb_Callback(hObject, eventdata, handles)
% hObject    handle to pozice_chyb (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 pozice_chyb as text
%        str2double(get(hObject,'String')) returns contents of pozice_chyb as a double


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



function chyb_poly_Callback(hObject, eventdata, handles)
% hObject    handle to chyb_poly (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 chyb_poly as text
%        str2double(get(hObject,'String')) returns contents of chyb_poly as a double


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


% --- Executes on button press in help_nalvekchyb.
function help_nalvekchyb_Callback(hObject, eventdata, handles)
% hObject    handle to help_nalvekchyb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Vektor chyb je vytvořen z nalezených pozic a hodnot chyb','Help','help');


% --- Executes on button press in help_pozice.
function help_pozice_Callback(hObject, eventdata, handles)
% hObject    handle to help_pozice (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Pozice je nalezena Chienovým vyhledáváním','Help','help');

% --- Executes on button press in help_syndromy.
function help_syndromy_Callback(hObject, eventdata, handles)
% hObject    handle to help_syndromy (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Syndromy jsou počítány postupným dosazováním kořenů generujícího polynomu','Help','help');


function syndromyc_Callback(hObject, eventdata, handles)
% hObject    handle to syndromyc (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 syndromyc as text
%        str2double(get(hObject,'String')) returns contents of syndromyc as a double


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


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


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


% --- 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)
cd ..
main_gui;
% cd vyukovy
% Hint: delete(hObject) closes the figure
delete(hObject);


% --- Executes on button press in diagram.
function diagram_Callback(hObject, eventdata, handles)
% hObject    handle to diagram (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 global zobrazdiagram;
        if zobrazdiagram == 1;
            PGZdiagram
        else
            BMdiagram
        end

% --- Executes on button press in diagram_help.
function diagram_help_Callback(hObject, eventdata, handles)
% hObject    handle to diagram_help (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
msgbox ('Zobrazí vývojový diagram pro BM a PGZ metodu','Help','help');



function opravene_slovo_Callback(hObject, eventdata, handles)
% hObject    handle to text36 (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 text36 as text
%        str2double(get(hObject,'String')) returns contents of text36 as a double


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


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