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

% Last Modified by GUIDE v2.5 13-May-2013 11:40:28

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

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

% Update handles structure
guidata(hObject, handles);

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


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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% po spuštění
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global obraz_s_textem citac;
global pocitadlo_vyber bylo_vlozeno;

pocitadlo_vyber = 0;
citac = 1;
obraz_s_textem = ones(3507,2496);
imshow(obraz_s_textem);
bylo_vlozeno = 1;

% nastavení oken
if exist('data\okna.mat') == 2
    load 'data\okna.mat'
else
    okno1 = 'Nic';
    okno2 = 'Nic';
    okno5 = 'Nic';
    okno6 = 'Nic';
    okno7 = 'Nic';
    okno8 = 'Nic';
    okno9 = 'Nic';
end

set(findobj('tag','edit1'),'string', okno1);
set(findobj('tag','edit2'),'string', okno2);
set(findobj('tag','edit5'),'string', okno5);
set(findobj('tag','edit6'),'string', okno6);
set(findobj('tag','edit7'),'string', okno7);
set(findobj('tag','edit8'),'string', okno8);
set(findobj('tag','edit9'),'string', okno9);

% zjištění verze matlabu
global verze velikost_textu_ulozen;
verze = version( '-release');

set(findobj('tag','edit3'),'string', strcat(['Byla rozpoznána verze ', verze]));

if str2double(verze(end-2:end-1)) >= 11
    verze = 1;%novější matlab
else
    verze = 0;% starší matlab
end

% na tvrdo zvolená verze pro matlab starší než 2011
% verze = 0;

% okno pro zadání textu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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

% okno pro zadání počtu kolonek
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% okna pro kolonky, řádek, výběr a osu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (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 edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (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 edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (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 edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (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 edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double


% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (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 edit8_Callback(hObject, eventdata, handles)
% hObject    handle to edit8 (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 edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double


% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

% uložení naposled zadaných textů
okno1 =  get(handles.edit1,'String');
okno2 =  get(handles.edit2,'String');
okno5 =  get(handles.edit5,'String');
okno6 =  get(handles.edit6,'String');
okno7 =  get(handles.edit7,'String');
okno8 =  get(handles.edit8,'String');
okno9 =  get(handles.edit9,'String');

save('data\okna.mat', 'okno1','okno2','okno5', 'okno6','okno7','okno8','okno9');

close;
clc;
clear all;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% uložení dokumentu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in ulozit.
function ulozit_Callback(hObject, eventdata, handles)
% hObject    handle to ulozit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global obraz_s_textem citac souradnice_kolonky_necele souradnice_cara_necele;
global souradnice_osa_necele souradnice_zaskrt_necele pocitadlo_vyber;
global text_kolonky_necele text_zaskrt_necele text_osa_necele text_cara_necele;

if pocitadlo_vyber ~= 0
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'Nelze uložit');
    return;
end

[file,path] = uiputfile('VYSTUP\vystupni_obrazek.bmp');
tecka = find(file == '.');

if length(path) > 2
    set(findobj('tag','edit3'),'BackgroundColor', 'green');
    set(findobj('tag','edit3'),'string', strcat('Vyčkejte!'));
    
    % nahrání formátu formuláře
    load data\ulozeny_format

    % přidání značky pro ohraničení a rotaci
    znacky = obraz_s_textem(:,:,citac);
    rezerva1 = round(okrajH/2);          % nahoru
    rezerva2 = round(okrajL/2);           % doleva
    rezerva3 = round(okrajD/2);          %dolu
    rezerva4 = round(okrajP/2);           % doprava
    
    znacky(okrajH-rezerva1:okrajH+199-rezerva1,okrajL-rezerva2:okrajL+19-rezerva2) = 0;                                                   % horní svislý
    znacky(okrajH-rezerva1:okrajH+19-rezerva1,okrajL-rezerva2:okrajL+199-rezerva2) = 0;                                                   % horní vodorovný
    znacky(end-okrajD-200+rezerva3:end-okrajD+rezerva3,end-okrajP-20+rezerva4:end-okrajP+rezerva4) = 0;                % dolní svislý
    znacky(end-okrajD-20+rezerva3:end-okrajD+rezerva3,end-2000-okrajP+rezerva4:end-okrajP+rezerva4) = 0;              % dolní vodorovný
   
    imwrite(znacky,strcat(path,file));
    
    %% uložení souřadnic testových polí
    celkova_velikost = [3507-rezerva1-rezerva3,2496-rezerva2-rezerva4];
    souradnice_cara = souradnice_cara_necele;
    souradnice_kolonky = souradnice_kolonky_necele;
    souradnice_osa = souradnice_osa_necele;
    souradnice_zaskrt = souradnice_zaskrt_necele;
   
    text_kolonky = char(text_kolonky_necele);
    text_zaskrt = char(text_zaskrt_necele);
    text_osa = char(text_osa_necele);
    text_cara = char(text_cara_necele);
    
    save_file = strcat(path,file(1:tecka-1),'.mat');
    save(save_file, 'celkova_velikost','souradnice_cara','souradnice_kolonky', ...
         'souradnice_osa','souradnice_zaskrt','text_kolonky','text_zaskrt',...
         'text_osa','text_cara');
     
     % uložení naposled zadaných textů
     okno1 =  get(handles.edit1,'String');
     okno2 =  get(handles.edit2,'String');
     okno5 =  get(handles.edit5,'String');
     okno6 =  get(handles.edit6,'String');
     okno7 =  get(handles.edit7,'String');
     okno8 =  get(handles.edit8,'String');
     okno9 =  get(handles.edit9,'String');
     
     save('data\okna.mat', 'okno1','okno2','okno5', 'okno6','okno7','okno8','okno9');

%%
    set(findobj('tag','edit3'),'string', strcat({'Uloženo do: '},path));
    set(findobj('tag','edit3'),'BackgroundColor', 'white');
else
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'neUloženo');
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% vrátí poslední akce (zpět)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in smazat.
function smazat_Callback(hObject, eventdata, handles)
% hObject    handle to smazat (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global obraz_s_textem citac poradnik bylo_vlozeno  pocitadlo_vyber pocet_vyber;
global text_kolonky_necele text_zaskrt_necele text_osa_necele text_cara_necele;
global souradnice_osa_necele souradnice_zaskrt_necele souradnice_kolonky_necele souradnice_cara_necele;

if pocitadlo_vyber ~= 0    
    set(findobj('tag','edit3'),'string', 'Nelze zpět, nejprve ukončete vkládání');         
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    return;
end

if citac >= 2 
    bylo_vlozeno = 0;
    citac = citac - 1;
    imshow(obraz_s_textem(:,:,citac));
    
    switch poradnik(citac)
        case 0
        case 1
            rozmer = size(souradnice_kolonky_necele);
            pomocna = souradnice_kolonky_necele;
            souradnice_kolonky_necele = pomocna(1:rozmer(2)-4);

            rozmer = size(text_kolonky_necele);
            pomocna = text_kolonky_necele;
            text_kolonky_necele = pomocna(1:rozmer(1)-1,:);
        case 2
            rozmer = size(souradnice_zaskrt_necele);
            pomocna = souradnice_zaskrt_necele;
            souradnice_zaskrt_necele = pomocna(1:rozmer(2)-4*(pocet_vyber-1));
 
            rozmer = size(text_zaskrt_necele);
            pomocna = text_zaskrt_necele;
            text_zaskrt_necele = pomocna(1:rozmer(1)-pocet_vyber,:);
                      
        case 3        
            rozmer = size(souradnice_cara_necele);
            pomocna = souradnice_cara_necele;
            souradnice_cara_necele = pomocna(1:rozmer(2)-4);

            rozmer = size(text_cara_necele);
            pomocna = text_cara_necele;
            text_cara_necele = pomocna(1:rozmer(1)-1,:);
        case 4      
            rozmer = size(souradnice_osa_necele);
            pomocna = souradnice_osa_necele;
            souradnice_osa_necele = pomocna(1:rozmer(2)-4);

            rozmer = size(text_osa_necele);
            pomocna = text_osa_necele;
            text_osa_necele = pomocna(1:rozmer(1)-1,:);
    end
    
    set(findobj('tag','edit3'),'BackgroundColor', 'white');
else
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'Už nelze zpět');
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% tlačítko vpřed
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global obraz_s_textem citac poradnik bylo_vlozeno pocet_vyber pocitadlo_vyber;
global text_kolonky_necele text_zaskrt_necele text_osa_necele text_cara_necele;
global text_kolonky_necele2 text_zaskrt_necele2 text_osa_necele2 text_cara_necele2;
global souradnice_osa_necele souradnice_zaskrt_necele souradnice_kolonky_necele souradnice_cara_necele;
global souradnice_osa_necele2 souradnice_zaskrt_necele2 souradnice_kolonky_necele2 souradnice_cara_necele2;

if pocitadlo_vyber ~= 0    
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'Nelze vpřed, nejprve ukončete vkládání');                
    return;
end

velikost = size(obraz_s_textem);

if bylo_vlozeno == 0 && citac < velikost(3)
    switch poradnik(citac)
        case 1          
            rozmer = size(souradnice_kolonky_necele);
            souradnice_kolonky_necele = souradnice_kolonky_necele2(1:rozmer(2)+4);
            
            rozmer = size(text_kolonky_necele);
            text_kolonky_necele = text_kolonky_necele2(1:rozmer(1)+1,:);
        case 2
            rozmer = size(souradnice_zaskrt_necele);
            souradnice_zaskrt_necele = souradnice_zaskrt_necele2(1:rozmer(2)+pocet_vyber*4-4);

            rozmer = size(text_zaskrt_necele);
            text_zaskrt_necele = text_zaskrt_necele2(1:rozmer(1)+pocet_vyber,:);
        case 3        
            rozmer = size(souradnice_cara_necele);
            souradnice_cara_necele = souradnice_cara_necele2(1:rozmer(2)+4);

            rozmer = size(text_cara_necele);
            text_cara_necele = text_cara_necele2(1:rozmer(1)+1,:);
        case 4      
            rozmer = size(souradnice_osa_necele);
            souradnice_osa_necele = souradnice_osa_necele2(1:rozmer(2)+4);

            rozmer = size(text_osa_necele);
            text_osa_necele = text_osa_necele2(1:rozmer(1)+1,:);
    end
    
    citac = citac + 1;
    imshow(obraz_s_textem(:,:,citac));
    set(findobj('tag','edit3'),'BackgroundColor', 'white');
else
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'Už nelze vpřed');
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% vložení textu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global citac obraz_s_textem poradnik bylo_vlozeno;
global pocitadlo_vyber nazev_vyber verze;


if pocitadlo_vyber == 0.5
        pocitadlo_vyber = 0;
        poradnik(citac) = 2;   
        bylo_vlozeno = 1;
elseif pocitadlo_vyber ~= 0
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'Nelze vkládat text, nejprve ukončete vkládání výběru');                
    return;
% pokud mačkám jenom vložení textu
else
    pocitadlo_vyber = 1;
end

% nahrání formátu formuláře
load data\ulozeny_format

vyska_radku = velikost_textu + mezera;
[rozdeleniX, rozdeleniY] = size(rozdeleni);

[x,y] = ginput(1);

x = round(x);
y = round(y);
XX = okrajL + 1;

% pokud je mimo zobrazení tak přeskoč
if y > 1 && y < rozdeleniX
    % uprava, pokud je kliknuto do řádku
    if rozdeleni(y,XX) < 0.5
        y = y - round(vyska_radku/2);
    end
    
    % pokud je kliknuto mimo okraje
    if y <= okrajH
        y = okrajH + 10;
    elseif y >= rozdeleniX - okrajD
        y = rozdeleniX - okrajD - 1;
    end
    
    % nalezeni horního řádku
    while rozdeleni(y,XX) > 0.5
        y = y - 1;
    end
end  
    YY = y + 1;

%%%%%%%%%%%%%%%%
% vložení textu do přechodného souboru
if pocitadlo_vyber == 0
    textu = sprintf( get(handles.edit7,'String'));
    nazev_vyber = textu;
    pocitadlo_vyber = 1;
else
    textu = sprintf( get(handles.edit1,'String'));
    pocitadlo_vyber = 0;
end

hacky = find(textu=='ě'|textu =='š'|textu=='č'|textu=='ř'|textu =='ž'|textu=='Ě'|textu =='Š'|textu=='Č'|textu=='Ř'|textu =='Ž'...
|textu=='é'|textu =='É'|textu=='í'|textu=='Í'|textu =='á'|textu=='Á'|textu =='ý'|textu=='Ý'|textu=='ú'|textu =='Ú'|textu=='ů'|textu =='Ů');

% pokud nebyl vložen text
delka_textu = length(textu);
if delka_textu == 0
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'Nezadali jste text');
    return
end
% výběr metody zadávání textu
% verze == 0 stará verze matlabu
if length(hacky) >= 1 || verze == 0
    velikost_textu = velikost_textu - 20;
    papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
    figure(1)
    imshow(papirek);
    text(velikost_textu/7,2*velikost_textu-velikost_textu/2,textu,'FontSize',velikost_textu);%'nodisplay');
    F = getframe;
    close 1
    obraz = frame2im(F);
    
    % uprava textu, prahování
    napis = im2double(rgb2gray(obraz));
else
    papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
    H = vision.TextInserter(textu);
    H.Color = 0;
    H.FontSize = velikost_textu;
    H.Location = [10 velikost_textu];
    obraz = step(H, papirek);
    
    % uprava textu, prahování
    napis = im2double(obraz);
end

napis = napis(1:end-10,1:end-10);
vystup_text = napis;
vystup_text(napis > 0.5) = 0;
vystup_text(napis < 0.5) = 1;

[prumetV, poziceV] = funkce_prumet(vystup_text,'V');
[prumetH, poziceH] = funkce_prumet(vystup_text,'H');

% ořezání
vysledny_textB = napis(poziceV(2):poziceV(end-1),poziceH(2):poziceH(end-1));
[vyska, sirka] = size(vysledny_textB);

% zarovnání vlevo
if get(handles.radiobutton1,'Value') == 1
    XX = okrajL + 1;
% zarovnání na střed 
elseif get(handles.radiobutton2,'Value') == 1
    XX = (rozdeleniY - sirka)/2;
% zarovnání vpravo
elseif get(handles.radiobutton3,'Value') == 1
    XX = rozdeleniY - sirka - okrajP;
end

% zijštění polohy umístění
papir = obraz_s_textem(:,:,citac);
[papirX, papirY] = size(papir);
imshow(papir);

x = XX;
y = YY;

if (vyska + y) < papirX && (sirka + x) < papirY && x > 0 && y > 0   
    y1 = y;
    y2 = y + vyska - 1;
    x1 = x;
    x2 = x + sirka - 1;
    papir(y1 : y2, x1 : x2) = vysledny_textB;
    
elseif x < 0 || y < 0 || x > papirY || y > papirX
    set(findobj('tag','edit3'),'string', 'Ukazatel je mimo papír');
        set(findobj('tag','edit3'),'BackgroundColor', 'red');
elseif (vyska + y) > papirX || (sirka + x) > papirY
    set(findobj('tag','edit3'),'string', 'Objekt se nevejde');  
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
end

imshow(papir);

% uložení
citac = citac + 1;
obraz_s_textem(:,:,citac) = papir;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% vložení kolonky 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global citac obraz_s_textem poradnik bylo_vlozeno;
global souradnice_kolonky_necele text_kolonky_necele pocitadlo_vyber; 
global souradnice_kolonky_necele2 text_kolonky_necele2 verze;

if pocitadlo_vyber ~= 0    
    set(findobj('tag','edit3'),'string', 'Nelze vkládat kolonky, nejprve ukončete vkládání výběru');  
    set(findobj('tag','edit3'),'BackgroundColor', 'red');              
    return;
end

poradnik(citac) = 1;
bylo_vlozeno = 1;

% nahrání formátu formuláře
load data\ulozeny_format

vyska_radku = velikost_textu + mezera;
[rozdeleniX, rozdeleniY] = size(rozdeleni);

[x,y] = ginput(1);

x = round(x);
y = round(y);
XX = okrajL + 1;

% pokud je mimo zobrazení tak přeskoč
if y > 1 && y < rozdeleniX
    % uprava, pokud je kliknuto do řádku
    if  y > 1 && rozdeleni(y,XX) < 0.5
        y = y - round(vyska_radku/2);
    end
    
    % pokud je kliknuto mimo okraje
    if y > 1 && y <= okrajH
        y = okrajH + 10;
    elseif y > 1 && y >= rozdeleniX - okrajD
        y = rozdeleniX - okrajD - 1;
    end    
    
    % nalezeni horního řádku
    while rozdeleni(y,XX) > 0.5
        y = y - 1;
    end
end
YY = y + 1;

%%%%%%%%%%%%%%%%

% vytvoření tabulky
vyska = velikost_textu+20;
sirka_puvodni = velikost_textu;
sirka_cary = 5;

% počet kolonek
pocet = str2double(get(handles.edit2,'String'));
if pocet <  1  || isnan(pocet) == 1
    set(findobj('tag','edit3'),'string', 'Počet kolonek je špatně vyplněn');
    set(findobj('tag','edit3'),'BackgroundColor', 'red');  
    set(findobj('tag','edit2'),'BackgroundColor', 'red');
    return;
else
    set(findobj('tag','edit3'),'BackgroundColor', 'white');
    set(findobj('tag','edit2'),'BackgroundColor', 'white');
end
% celkova délka
sirka = (sirka_cary + sirka_puvodni) * pocet;

tabulka = ones(vyska,sirka);
tabulka(1:vyska,1:sirka_cary + 1) = 0;              % první svislá
tabulka(1:sirka_cary + 1,1:sirka) = 0;              % horní vodorovná
tabulka(vyska - sirka_cary:vyska,1:sirka) = 0;      % spodní vodorovná

% další svislé čáry
sirka = 0;
while(pocet > 0)
    
    if sirka == 0
        sirka = 1 + 2*sirka_cary + sirka + sirka_puvodni;
    else
        sirka = sirka + sirka_puvodni + sirka_cary;
    end
    
    tabulka(1:vyska,sirka - sirka_cary:sirka) = 0;
    
    pocet = pocet - 1; 
end
%%%%%%%%%%%%%%%%
% vložení textu do přechodného souboru
textu = sprintf( get(handles.edit5,'String'));
hacky = find(textu=='ě'|textu =='š'|textu=='č'|textu=='ř'|textu =='ž'|textu=='Ě'|textu =='Š'|textu=='Č'|textu=='Ř'|textu =='Ž'...
|textu=='é'|textu =='É'|textu=='í'|textu=='Í'|textu =='á'|textu=='Á'|textu =='ý'|textu=='Ý'|textu=='ú'|textu =='Ú'|textu=='ů'|textu =='Ů');

% pokud nebyl vložen text
delka_textu = length(textu);
if delka_textu == 0
    set(findobj('tag','edit3'),'string', 'Nezadali jste text');
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    return
end

if length(hacky) >= 1 || verze == 0
    velikost_textu = velikost_textu - 20;
    papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
    figure(1)
    imshow(papirek);
    text(velikost_textu/7,2*velikost_textu-velikost_textu/2,textu,'FontSize',velikost_textu);
    F = getframe;
    close 1
    obraz = frame2im(F);
    
    % uprava textu, prahování
    napis = im2double(rgb2gray(obraz));
else
    H = vision.TextInserter(textu);
    H.Color = 0;
    H.FontSize = velikost_textu;
    H.Location = [10 velikost_textu];
    
    papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
    obraz = step(H, papirek);
    
    % uprava textu, prahování
    napis = im2double(obraz);
end

napis = napis(1:end-10,1:end-10);
vystup_text = napis;
vystup_text(napis > 0.5) = 0;
vystup_text(napis < 0.5) = 1;

[prumetV, poziceV] = funkce_prumet(vystup_text,'V');
[prumetH, poziceH] = funkce_prumet(vystup_text,'H');

% ořezání
vysledny_textB = napis(poziceV(2):poziceV(end-1),poziceH(2):poziceH(end-1));
[vyska2, sirka2] = size(vysledny_textB);

% zarovnání vlevo
if get(handles.radiobutton1,'Value') == 1
    XX = okrajL + 1;
% zarovnání na střed 
elseif get(handles.radiobutton2,'Value') == 1
    XX = round((rozdeleniY - sirka - sirka2)/2);
% zarovnání vpravo
elseif get(handles.radiobutton3,'Value') == 1
    XX = rozdeleniY - sirka - sirka2 - okrajP;
end

% zijštění polohy umístění
papir = obraz_s_textem(:,:,citac);
[papirX, papirY] = size(papir);
imshow(papir);
x = XX;
y = YY;

if (vyska + vyska2 + y) < papirX && (sirka + sirka2 + x) < papirY && x > 0 && y > 0
    y1 = y;
    y2 = y + vyska2 - 1;
    x1 = x;
    x2 = x + sirka2 - 1;
    papir(y1 : y2, x1 : x2) = vysledny_textB;
    
    y1 = y - vyska/4;
    y2 = y + 3*vyska/4 - 1;
    x1 = sirka2 + velikost_textu + x;
    x2 = sirka2 + velikost_textu + x + sirka - 1;
    papir(round(y1) : round(y2), x1 : x2) = tabulka;

    % uložení souřadnic
    rezerva = round(vyska/3);
    y1 = y1 - rezerva - okrajH/2;
    y2 = y2 + rezerva - okrajH/2;
    x1 = x1 - rezerva - okrajL/2;
    x2 = x2 + rezerva - okrajL/2;     
    radek = length(souradnice_kolonky_necele);
    souradnice_kolonky_necele(radek + 1:radek + 4) = [y1,y2, x1,x2];
    souradnice_kolonky_necele2 = souradnice_kolonky_necele;
        
    % uloží text
    text_kolonky_necele(radek/4+1,1:length(textu)) = textu;
    text_kolonky_necele2 = text_kolonky_necele;
    
elseif y < 0 || y > papirX
        set(findobj('tag','edit3'),'BackgroundColor', 'red');
        set(findobj('tag','edit3'),'string', 'Ukazatel je mimo papír');
elseif (vyska + y) > papirX || (sirka + x) > papirY    
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'Objekt se nevejde');
end

imshow(papir);

% uložení
citac = citac + 1;
obraz_s_textem(:,:,citac) = papir;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ukončení vkládání výběru (zašktávacích políček)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton15 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global pocitadlo_vyber nazev_vyber obraz_s_textem_vyber;
global text_zaskrt_necele text_zaskrt_necele2; %souradnice_zaskrt_necele;
global citac obraz_s_textem poradnik bylo_vlozeno pocet_vyber verze;

if pocitadlo_vyber == 0
    set(findobj('tag','edit3'),'string', 'Nelze ukončit co nebylo započato');
     set(findobj('tag','edit3'),'BackgroundColor', 'red');
     return;
end

if pocitadlo_vyber == 1
    set(findobj('tag','edit3'),'string', 'Nebyla vložena volba');  
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    return;
end

% celkové uložení
velikost = size(text_zaskrt_necele);
mezi_vysledek = strcat('+',nazev_vyber);
text_zaskrt_necele(velikost(1) + 1,1:length(mezi_vysledek)) =  mezi_vysledek;
text_zaskrt_necele2 = text_zaskrt_necele;

% uložení obrazu
poradnik(citac) = 2;
bylo_vlozeno = 1;
papir = obraz_s_textem_vyber(:,:,pocitadlo_vyber);
% citac = citac + 1;
obraz_s_textem(:,:,citac) = papir;

set(findobj('tag','edit3'),'string', 'Vkládání ukončeno');
set(findobj('tag','edit3'),'BackgroundColor', 'white');

pocet_vyber = pocitadlo_vyber;
pocitadlo_vyber = 0;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% vložení výběru
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global citac obraz_s_textem; %poradnik bylo_vlozeno;
global souradnice_zaskrt_necele text_zaskrt_necele;
global souradnice_zaskrt_necele2 text_zaskrt_necele2;
global pocitadlo_vyber obraz_s_textem_vyber verze;

% poprvé vloží pouze text nad výběr
if pocitadlo_vyber == 0
    pocitadlo_vyber = 0.5;
    pushbutton6_Callback(hObject, eventdata, handles);
    set(findobj('tag','edit3'),'string', 'Vkládání výběru');
    set(findobj('tag','edit3'),'BackgroundColor', 'blue');
    return;
end

pocitadlo_vyber = pocitadlo_vyber + 1;

% nahrání formátu formuláře
load data\ulozeny_format

vyska_radku = velikost_textu + mezera;
[rozdeleniX, rozdeleniY] = size(rozdeleni);

[x,y] = ginput(1);

x = round(x);
y = round(y);
XX = okrajL + 1;

% pokud je mimo zobrazení tak přeskoč
if y > 1 && y < rozdeleniX
    % uprava, pokud je kliknuto do řádku
    if  y > 1 && rozdeleni(y,XX) < 0.5
        y = y - round(vyska_radku/2);
    end
    
    % pokud je kliknuto mimo okraje
    if y > 1 && y <= okrajH
        y = okrajH + 10;
    elseif y > 1 && y >= rozdeleniX - okrajD
        y = rozdeleniX - okrajD - 1;
    end    
    
    % nalezeni horního řádku
    while rozdeleni(y,XX) > 0.5
        y = y - 1;
    end
end
YY = y + 1;

%%%%%%%%%%%%%%%%

% vytvoření tabulky
vyska = velikost_textu;%80
sirka_puvodni = velikost_textu;%80
sirka_cary = 5;


% počet kolonek
pocet = 1;
% celkova délka
sirka = (sirka_cary + sirka_puvodni) * pocet;

tabulka = ones(vyska,sirka);
tabulka(1:vyska,1:sirka_cary + 1) = 0;              % první svislá
tabulka(1:sirka_cary + 1,1:sirka) = 0;              % horní vodorovná
tabulka(vyska - sirka_cary:vyska,1:sirka) = 0;      % spodní vodorovná
tabulka(1:vyska,sirka - sirka_cary:sirka) = 0;      % poslední svislá

%%%%%%%%%%%%%%%%
% vložení textu do přechodného souboru
textu = sprintf( get(handles.edit7,'String'));

hacky = find(textu=='ě'|textu =='š'|textu=='č'|textu=='ř'|textu =='ž'|textu=='Ě'|textu =='Š'|textu=='Č'|textu=='Ř'|textu =='Ž'...
|textu=='é'|textu =='É'|textu=='í'|textu=='Í'|textu =='á'|textu=='Á'|textu =='ý'|textu=='Ý'|textu=='ú'|textu =='Ú'|textu=='ů'|textu =='Ů');

% pokud nebyl vložen text
delka_textu = length(textu);
if delka_textu == 0
    set(findobj('tag','edit3'),'string', 'Nezadali jste text');
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    return
end

if length(hacky) >= 1 || verze == 0 
    velikost_textu = velikost_textu - 20;
    papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
    figure(1)
    imshow(papirek);
    text(velikost_textu/7,2*velikost_textu-velikost_textu/2,textu,'FontSize',velikost_textu);
    F = getframe;
    close 1
    obraz = frame2im(F);
    
    % uprava textu, prahování
    napis = im2double(rgb2gray(obraz));
else
    H = vision.TextInserter(textu);
    H.Color = 0;
    H.FontSize = velikost_textu;
    H.Location = [10 velikost_textu];
    
    papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
    obraz = step(H, papirek);
    
    % uprava textu, prahování
    napis = im2double(obraz);
end

napis = napis(1:end-10,1:end-10);
vystup_text = napis;
vystup_text(napis > 0.5) = 0;
vystup_text(napis < 0.5) = 1;

[prumetV, poziceV] = funkce_prumet(vystup_text,'V');
[prumetH, poziceH] = funkce_prumet(vystup_text,'H');

% ořezání
vysledny_textB = napis(poziceV(2):poziceV(end-1),poziceH(2):poziceH(end-1));
[vyska2, sirka2] = size(vysledny_textB);

%%%

% zarovnání vlevo
if get(handles.radiobutton1,'Value') == 1
    XX = okrajL + 1;
% zarovnání na střed 
elseif get(handles.radiobutton2,'Value') == 1
    XX = round((rozdeleniY - sirka - sirka2)/2);
% zarovnání vpravo
elseif get(handles.radiobutton3,'Value') == 1
    XX = rozdeleniY - sirka - sirka2 - okrajP;
end

% zijštění polohy umístění
if pocitadlo_vyber == 2
    papir = obraz_s_textem(:,:,citac);
else
    papir = obraz_s_textem_vyber(:,:,pocitadlo_vyber-1);
end
[papirX, papirY] = size(papir);
imshow(papir);
x = XX;
y = YY;

if (vyska + vyska2 + y) < papirX && (sirka + sirka2 + x) < papirY && x > 0 && y > 0
    % vloží čtvereček 
    y1 = y;
    y2 = y + vyska - 1;
    x1 = x;
    x2 = x + sirka - 1;
    papir(y1 : y2, x1 : x2) = tabulka;
    
    % uloží souřadnic     
    rezerva = round(vyska/3);
    y1 = y1 - rezerva - okrajH/2;
    y2 = y2 + rezerva - okrajH/2;
    x1 = x1 - rezerva - okrajL/2;
    x2 = x2 + rezerva - okrajL/2; 
    radek = length(souradnice_zaskrt_necele);
    souradnice_zaskrt_necele(radek + 1:radek + 4) =  [y1,y2, x1,x2];
    souradnice_zaskrt_necele2 = souradnice_zaskrt_necele;
    % vloží text za čtvereček (mezera je šířkou čtverečku)
    papir(y : y + vyska2 - 1, x + 2*sirka_puvodni : x + 2*sirka_puvodni + sirka2 - 1) = vysledny_textB;
          
    % uložení textu
    radek = size(text_zaskrt_necele);
    text_zaskrt_necele(radek(1)+1,1:length(textu)) = textu;
    text_zaskrt_necele2 = text_zaskrt_necele;
    
elseif y < 0 || y > papirX
    set(findobj('tag','edit3'),'string', 'Ukazatel je mimo papír');
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
end

imshow(papir);

obraz_s_textem_vyber(:,:,pocitadlo_vyber) = papir;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% vložení řádku
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global citac obraz_s_textem poradnik bylo_vlozeno;
global souradnice_cara_necele text_cara_necele pocitadlo_vyber;
global souradnice_cara_necele2 text_cara_necele2 verze;

if pocitadlo_vyber ~= 0    
    set(findobj('tag','edit3'),'string', 'Nelze vkládat řádek, nejprve ukončete vkládání výběru');                
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    return;
end

poradnik(citac) = 3;
bylo_vlozeno = 1;

% nahrání formátu formuláře
load data\ulozeny_format

vyska_radku = velikost_textu + mezera;
[rozdeleniX, rozdeleniY] = size(rozdeleni);

[x,y] = ginput(1);

x = round(x);
y = round(y);
XX = okrajL + 1;

% pokud je mimo zobrazení tak přeskoč
if y > 1 && y < rozdeleniX
    % uprava, pokud je kliknuto do řádku
    if  y > 1 && rozdeleni(y,XX) < 0.5
        y = y - round(vyska_radku/2);
    end
    
    % pokud je kliknuto mimo okraje
    if y > 1 && y <= okrajH
        y = okrajH + 10;
    elseif y > 1 && y >= rozdeleniX - okrajD
        y = rozdeleniX - okrajD - 1;
    end    
    
    % nalezeni horního řádku
    while rozdeleni(y,XX) > 0.5
        y = y - 1;
    end
end
YY = y + 1;

%%%%%%%%%%%%%%%%

% vytvoření tabulky
sirka_puvodni = velikost_textu;%80
vyska = 5;
vyska_textu = velikost_textu-10;%70

% počet kolonek
pocet = str2num(get(handles.edit9,'String'));
% celkova délka
sirka = (vyska + sirka_puvodni) * pocet;

tabulka = ones(vyska_textu,sirka);
tabulka(vyska_textu - vyska:vyska_textu,1:sirka) = 0;      % spodní vodorovná

%%%%%%%%
% vložení textu do přechodného souboru
textu = sprintf( get(handles.edit6,'String'));

hacky = find(textu=='ě'|textu =='š'|textu=='č'|textu=='ř'|textu =='ž'|textu=='Ě'|textu =='Š'|textu=='Č'|textu=='Ř'|textu =='Ž'...
|textu=='é'|textu =='É'|textu=='í'|textu=='Í'|textu =='á'|textu=='Á'|textu =='ý'|textu=='Ý'|textu=='ú'|textu =='Ú'|textu=='ů'|textu =='Ů');

% pokud nebyl vložen text
delka_textu = length(textu);
if delka_textu == 0
    set(findobj('tag','edit3'),'string', 'Nezadali jste text');
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    return
end

if length(hacky) >= 1 || verze == 0
    velikost_textu = velikost_textu - 20;
    papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
    figure(1)
    imshow(papirek);
    text(velikost_textu/7,2*velikost_textu-velikost_textu/2,textu,'FontSize',velikost_textu);%'nodisplay');
    F = getframe;
    close 1
    obraz = frame2im(F);
    
    % uprava textu, prahování
    napis = im2double(rgb2gray(obraz));
else
    H = vision.TextInserter(textu);
    H.Color = 0;
    H.FontSize = velikost_textu;
    H.Location = [10 velikost_textu];
    
    papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
    obraz = step(H, papirek);
    
    % uprava textu, prahování
    napis = im2double(obraz);
end

napis = napis(10:end-10,1:end-10);
vystup_text = napis;
vystup_text(napis > 0.5) = 0;
vystup_text(napis < 0.5) = 1;


[prumetV, poziceV] = funkce_prumet(vystup_text,'V');
[prumetH, poziceH] = funkce_prumet(vystup_text,'H');

% ořezání
vysledny_textB = napis(poziceV(2):poziceV(end-1),poziceH(2):poziceH(end-1));
[vyska2, sirka2] = size(vysledny_textB);

% zarovnání vlevo
if get(handles.radiobutton1,'Value') == 1
    XX = okrajL + 1;
% zarovnání na střed 
elseif get(handles.radiobutton2,'Value') == 1
    XX = round((rozdeleniY - sirka - sirka2)/2);
% zarovnání vpravo
elseif get(handles.radiobutton3,'Value') == 1
    XX = rozdeleniY - sirka - sirka2 - okrajP;
end

% zijštění polohy umístění
papir = obraz_s_textem(:,:,citac);
[papirX, papirY] = size(papir);
imshow(papir);
x = XX;
y = YY;


if (vyska + vyska2 + y) < papirX && (sirka + sirka2 + x) < papirY && x > 0 && y > 0
    y1 = y;
    y2 = y + vyska2 - 1;
    x1 = x;
    x2 = x + sirka2 - 1;
    papir(y1 : y2, x1 : x2) = vysledny_textB;
    
    y1 = y;
    y2 = y + vyska_textu - 1;
    x1 = x + velikost_textu + sirka2;
    x2 = x + velikost_textu + sirka2 + sirka - 1;
    papir(y1 : y2, x1 : x2) = tabulka;
        
    % uložení souřadnic
    rezerva = round(vyska_textu/3);
    y1 = y1 - rezerva - okrajH/2;
    y2 = y2 + rezerva - okrajH/2;
    x1 = x1 - rezerva - okrajL/2;
    x2 = x2 + rezerva - okrajL/2; 
    radek = length(souradnice_cara_necele);
    souradnice_cara_necele(radek + 1:radek + 4) =  [y1,y2, x1,x2];
    souradnice_cara_necele2 = souradnice_cara_necele;
    
    % uložení textu
    text_cara_necele(radek/4+1,1:length(textu)) = textu;
    text_cara_necele2 = text_cara_necele;
% chyba   
    
elseif y < 0 || y > papirX
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'Ukazatel je mimo papír');
end

imshow(papir);

% uložení
citac = citac + 1;
obraz_s_textem(:,:,citac) = papir;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% vložení osy
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global citac obraz_s_textem poradnik bylo_vlozeno;
global souradnice_osa_necele text_osa_necele pocitadlo_vyber;
global souradnice_osa_necele2 text_osa_necele2 verze;
global velikost_textu_ulozen;

if pocitadlo_vyber ~= 0    
    set(findobj('tag','edit3'),'string', 'Nelze vkládat osu, nejprve ukončete vkládání výběru');                
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    return;
end

poradnik(citac) = 4;
bylo_vlozeno = 1;

% nahrání formátu formuláře
load data\ulozeny_format

if velikost_textu < 40    
    set(findobj('tag','edit3'),'string', 'Byla zadána malá velikost písma');                
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    return;
end

load data\osa.mat

% generování osy
if velikost_textu ~= velikost_textu_ulozen
    sirka_osy = round(velikost_textu/7);
    velikost_osy = velikost_textu;% - 20;
    rozdeleniY = size(rozdeleni);

    osa = ones(velikost_osy,rozdeleniY(2) - okrajP - okrajL);
%     verze = 0;
    %% %%%% 0 %
    if verze == 0
        textu = '0 %';
        delka_textu = length(textu);
        velikost_textu0 = velikost_textu - 20;
        papirek = ones(velikost_textu0*3,delka_textu*velikost_textu0);
        figure(1)
        imshow(papirek);
        text(velikost_textu0/7,2*velikost_textu0-velikost_textu0/2,textu,'FontSize',velikost_textu0);%'nodisplay');
        F = getframe;
        close 1
        obraz = frame2im(F);
        
        % uprava textu, prahování
        napis = im2double(rgb2gray(obraz));
    else
        textu = '0 %%';
        delka_textu = length(textu);
        H = vision.TextInserter(textu);
        H.Color = 0;
        H.FontSize = velikost_textu;
        H.Location = [10 velikost_textu];
        
        papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
        obraz = step(H, papirek);
        
        % uprava textu, prahování
        napis = im2double(obraz);
    end
    napis = napis(1:end-10,1:end-10);
    vystup_text = napis;
    vystup_text(napis > 0.9) = 0;
    vystup_text(napis < 0.95) = 1;
    
    [prumetV, poziceV] = funkce_prumet(vystup_text,'V');
    [prumetH, poziceH] = funkce_prumet(vystup_text,'H');
    
    vysledny_textB = napis(poziceV(2):poziceV(end-1),poziceH(2):poziceH(end-1));
    [vyska, sirka] = size(vysledny_textB);
    
    x = 1;
    y = 1;
    osa(x:x+vyska-1,y:y+sirka-1) = vysledny_textB;
    %% %%%% 100 %
    if verze == 0
        textu = '100 %';
        delka_textu = length(textu);
        velikost_textu100 = velikost_textu - 20;
        papirek = ones(velikost_textu100*3,delka_textu*velikost_textu100);
        figure(1)
        imshow(papirek);
        text(velikost_textu100/7,2*velikost_textu100-velikost_textu100/2,textu,'FontSize',velikost_textu100);%'nodisplay');
        F = getframe;
        close 1
        obraz = frame2im(F);
        
        % uprava textu, prahování
        napis = im2double(rgb2gray(obraz));
    else
        textu = '100 %%';
        delka_textu = length(textu);
        H = vision.TextInserter(textu);
        H.Color = 0;
        H.FontSize = velikost_textu;
        H.Location = [10 velikost_textu];
        
        papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
        obraz = step(H, papirek);
        
        % uprava textu, prahování
        napis = im2double(obraz);
    end
    
    napis = napis(1:end-10,1:end-10);
    vystup_text = napis;
    vystup_text(napis > 0.9) = 0;
    vystup_text(napis < 0.95) = 1;
    
    [prumetV, poziceV] = funkce_prumet(vystup_text,'V');
    [prumetH, poziceH] = funkce_prumet(vystup_text,'H');
    
    vysledny_textB = napis(poziceV(2):poziceV(end-1),poziceH(2):poziceH(end-1));
    [vyska, sirka] = size(vysledny_textB);
    
    x = 1;
    osa(x:x+vyska-1,end-sirka+1:end) = vysledny_textB;
    
    %% %%%% osa %
    zacatek = round(velikost_textu/2);
    % prvni svysla
    osa(1:velikost_osy,5*zacatek:5*zacatek+sirka_osy) = 0;
    % druha svysla
    osa(1:velikost_osy,end-7*zacatek - sirka_osy : end- 7*zacatek) = 0;
    % vodorovna
    osa(round(velikost_osy/2)- round(sirka_osy/2) : round(velikost_osy/2) + round(sirka_osy/2),5*zacatek:end-7*zacatek) = 0;
    %%%%%
    velikost_textu_ulozen = velikost_textu;
    save('data\osa.mat', 'osa','velikost_textu_ulozen');
end

vyska_radku = velikost_textu + mezera;
[rozdeleniX, rozdeleniY] = size(rozdeleni);

[x,y] = ginput(1);

x = round(x);
y = round(y);
XX = okrajL + 1;

% pokud je mimo zobrazení tak přeskoč
if y > 1 && y < rozdeleniX
    % uprava, pokud je kliknuto do řádku
    if  y > 1 && rozdeleni(y,XX) < 0.5
        y = y - round(vyska_radku/2);
    end
    
    % pokud je kliknuto mimo okraje
    if y > 1 && y <= okrajH
        y = okrajH + 10;
    elseif y > 1 && y >= rozdeleniX - okrajD
        y = rozdeleniX - okrajD - 1;
    end    
    
    % nalezeni horního řádku
    while rozdeleni(y,XX) > 0.5
        y = y - 1;
    end
end
YY = y + 1;


%%%%%%%%

% vložení textu do přechodného souboru
textu = get(handles.edit8,'String');

hacky = find(textu=='ě'|textu =='š'|textu=='č'|textu=='ř'|textu =='ž'|textu=='Ě'|textu =='Š'|textu=='Č'|textu=='Ř'|textu =='Ž'...
|textu=='é'|textu =='É'|textu=='í'|textu=='Í'|textu =='á'|textu=='Á'|textu =='ý'|textu=='Ý'|textu=='ú'|textu =='Ú'|textu=='ů'|textu =='Ů');

% pokud nebyl vložen text
delka_textu = length(textu);
if delka_textu == 0
    set(findobj('tag','edit3'),'string', 'Nezadali jste text');
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    return
end

if length(hacky) >= 1 || verze == 0
    velikost_textu = velikost_textu - 20;
    papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
    figure(1)
    imshow(papirek);
    text(velikost_textu/7,2*velikost_textu-velikost_textu/2,textu,'FontSize',velikost_textu);
    F = getframe;
    close 1
    obraz = frame2im(F);
    
    % uprava textu, prahování
    napis = im2double(rgb2gray(obraz));
else
    H = vision.TextInserter(textu);
    H.Color = 0;
    H.FontSize = velikost_textu;
    H.Location = [10 velikost_textu];
    
    papirek = ones(velikost_textu*3,delka_textu*velikost_textu);
    obraz = step(H, papirek);
    
    % uprava textu, prahování
    napis = im2double(obraz);
end

napis = napis(10:end-10,1:end-10);
vystup_text = napis;
vystup_text(napis > 0.5) = 0;
vystup_text(napis < 0.5) = 1;

[prumetV, poziceV] = funkce_prumet(vystup_text,'V');
[prumetH, poziceH] = funkce_prumet(vystup_text,'H');

% ořezání
vysledny_textB = napis(poziceV(2):poziceV(end-1),poziceH(2):poziceH(end-1));
[vyska2, sirka2] = size(vysledny_textB);

% zarovnání vlevo
if get(handles.radiobutton1,'Value') == 1
    XX = okrajL + 1;
% zarovnání na střed 
elseif get(handles.radiobutton2,'Value') == 1
    XX = round((rozdeleniY - sirka2)/2);
% zarovnání vpravo
elseif get(handles.radiobutton3,'Value') == 1
    XX = rozdeleniY - sirka2 - okrajP;
end


% zijštění polohy umístění
papir = obraz_s_textem(:,:,citac);
[papirX, papirY] = size(papir);
[vyska, sirka] = size(osa);
imshow(papir);
x = XX;
y = YY;

if (vyska + vyska2 + y) < papirX && (sirka2 + x) < papirY && x > 0 && y > 0
    y1 = y;
    y2 = y + vyska2 - 1;
    x1 = x;
    x2 = x + sirka2 - 1;
    papir(y1 : y2, x1 : x2) = vysledny_textB;
    
    y1 = y + vyska2 + velikost_textu;
    y2 = y + vyska2 + velikost_textu + vyska - 1;
    x1 = okrajL + 1;
    x2 = okrajL + sirka;
    papir(y1 : y2, x1 : x2) = osa;

    % uložení souřadnic
    rezerva = round(vyska2/3);
    y1 = y1 - rezerva - okrajH/2;
    y2 = y2 + rezerva - okrajH/2;
    x1 = x1 - rezerva - okrajL/2;
    x2 = x2 + rezerva - okrajL/2; 
    radek = length(souradnice_osa_necele);
    souradnice_osa_necele(radek + 1:radek + 4) = [y1,y2, x1,x2];
    souradnice_osa_necele2 = souradnice_osa_necele;

    % uložení textu
    text_osa_necele(radek/4+1,1:length(textu)) = char(textu);
    text_osa_necele2 = text_osa_necele;

        
elseif y < 0 || y > papirX
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'Ukazatel je mimo papír');
elseif (vyska2 + y) > papirX || (sirka2 + x) > papirY
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'Objekt se nevejde');
end

imshow(papir);

% uložení
citac = citac + 1;
obraz_s_textem(:,:,citac) = papir;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Otevření rozpracovaného formuláře
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global citac obraz_s_textem pocitadlo_vyber;
global souradnice_kolonky_necele souradnice_cara_necele souradnice_osa_necele souradnice_zaskrt_necele;
global text_kolonky_necele text_zaskrt_necele text_osa_necele text_cara_necele;

if pocitadlo_vyber ~= 0
    set(findobj('tag','edit3'),'string', 'Nelze otevřít');
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    return;
end

[FileName,PathName] = uigetfile('VYSTUP\*.bmp');

if length(PathName) > 2
    obraz_s_textem(:,:,citac) = imread(strcat(PathName,FileName));
    imshow(obraz_s_textem(:,:,citac));
else
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    set(findobj('tag','edit3'),'string', 'Nebyl vybrán soubor');
    return;
end


%% nahrání souřadnic testových polí
save_file = strcat(PathName,FileName(1:end-4),'.mat');
if exist(save_file,'file') == 2
    load (save_file);
    set(findobj('tag','edit3'),'string', 'MAT soubor nalezen');
    set(findobj('tag','edit3'),'BackgroundColor', 'white');
else
    set(findobj('tag','edit3'),'string', 'Program nenalezl MAT soubor!');
    set(findobj('tag','edit3'),'BackgroundColor', 'red');
    return;
end

souradnice_cara_necele = souradnice_cara;
souradnice_kolonky_necele = souradnice_kolonky;
souradnice_osa_necele = souradnice_osa;
souradnice_zaskrt_necele = souradnice_zaskrt;

text_kolonky_necele = text_kolonky;
text_zaskrt_necele = text_zaskrt;
text_osa_necele = text_osa;
text_cara_necele = text_cara;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% spuštění dalšího gui kde se bude nastavovat okraje a řádky
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton14 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
rozvrzeni_formulare4;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% edit okno pro řádek
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (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 edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double


% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (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
