function varargout = rozpeti(varargin)
%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
%program vyuziva skripty: vesaky.m, konst.m a souvisici funkce
%spl_f.m, bpl_f.m
%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
% ROZPETI M-file for rozpeti.fig
%      ROZPETI, by itself, creates a new ROZPETI or raises the existing
%      singleton*.
%
%      H = ROZPETI returns the handle to a new ROZPETI or the handle to
%      the existing singleton*.
%
%      ROZPETI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ROZPETI.M with the given input arguments.
%
%      ROZPETI('Property','Value',...) creates a new ROZPETI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before rozpeti_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to rozpeti_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 rozpeti

% Last Modified by GUIDE v2.5 13-Feb-2009 11:34:39

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @rozpeti_OpeningFcn, ...
                   'gui_OutputFcn',  @rozpeti_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


function rozpeti_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;

guidata(hObject, handles);

initialize_gui(hObject, handles);       %inicializace


function varargout = rozpeti_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;

function edit1_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

function edit1_Callback(hObject, eventdata, handles)
%zadavani rozpeti
data = getappdata(gcbf, 'vstupy');
tmp = get(handles.edit1, 'String');
a=findstr(',',tmp);         %osetreni spravne syntaxe zadani
b=findstr(' ',tmp);
if (length(a)~=0|length(b)==0)
    errordlg('Císla oddìlujte mezerou. Desetinná èísla je tøeba zadat s desetinnou teèkou.')
else
    tmp=str2num(tmp);
    if length(tmp)<5
        errordlg('Zadejte nejménì 5 èísel (=4 vìšáky)')
    else
        if min(tmp)<=0
            errordlg('Vzdálenost mezi vìšáky musí být kladné èíslo')
        else
        data.x=abs(tmp);
    end
    end
end
set (hObject, 'String', num2str(data.x, '%-5.1f'));
set (handles.text13, 'String', num2str(sum(data.x),'%-5.1f'));
setappdata(gcbf, 'vstupy', data);


% bez pridavnych lan
function radiobutton1_Callback(hObject, eventdata, handles)
set(handles.radiobutton1, 'Value', 1);
set(handles.radiobutton2, 'Value', 0);
set(handles.edit2, 'Enable', 'off');
set(handles.edit8, 'Enable', 'off');
set(handles.edit9, 'Enable', 'off');


% zadani s pridavnymi lany
function radiobutton2_Callback(hObject, eventdata, handles)
set(handles.radiobutton1, 'Value', 0);
set(handles.radiobutton2, 'Value', 1);
set(handles.edit2, 'Enable', 'on');
set(handles.edit8, 'Enable', 'on');
set(handles.edit9, 'Enable', 'on');

function edit2_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% zadavan bez pridavnych lan
function edit2_Callback(hObject, eventdata, handles)
data = getappdata(gcbf, 'vstupy');
tmp = get(handles.edit2, 'String');
tmp=str2double(tmp);
if isnan(tmp)
    errordlg('Zadejte èíslo!');
else
    if (tmp/2<=data.x(1)|tmp/2<=data.x(end))
            errordlg('Pøídavné lano musí zasahovat za první vìšák!');
        else
        data.xpl=abs(tmp);
    end
end
set (hObject, 'String', data.xpl);
setappdata(gcbf, 'vstupy', data);

function edit4_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


%zadavani Ftd
function edit4_Callback(hObject, eventdata, handles)
data = getappdata(gcbf, 'vstupy');
tmp = get(handles.edit4, 'String');
tmp=str2double(tmp);
if isnan(tmp)
    errordlg('Zadejte èíslo!');
else
    data.Ftd=abs(tmp);
end
set (hObject, 'String', data.Ftd);
setappdata(gcbf, 'vstupy', data);

function edit5_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


%zadavani Fnl
function edit5_Callback(hObject, eventdata, handles)
data = getappdata(gcbf, 'vstupy');
tmp = get(handles.edit5, 'String');
tmp=str2double(tmp);
if isnan(tmp)
    errordlg('Zadejte èíslo!');
else
    data.Fnl=abs(tmp);
end
set (hObject, 'String', data.Fnl);
setappdata(gcbf, 'vstupy', data);

function edit6_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


%zadavani mtd
function edit6_Callback(hObject, eventdata, handles)
data = getappdata(gcbf, 'vstupy');
tmp = get(handles.edit6, 'String');
tmp=str2double(tmp);
if isnan(tmp)
    errordlg('Zadejte èíslo!');
else
    data.mtd=abs(tmp);
end
set (hObject, 'String', data.mtd);
setappdata(gcbf, 'vstupy', data);

function edit7_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


%zadavani mnl
function edit7_Callback(hObject, eventdata, handles)
data = getappdata(gcbf, 'vstupy');
tmp = get(handles.edit7, 'String');
tmp=str2double(tmp);
if isnan(tmp)
    errordlg('Zadejte èíslo!');
else
    data.mnl=abs(tmp);
end
set (hObject, 'String', data.mnl);
setappdata(gcbf, 'vstupy', data);

function edit8_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


%zadavani fpl
function edit8_Callback(hObject, eventdata, handles)
data = getappdata(gcbf, 'vstupy');
tmp = get(handles.edit8, 'String');
tmp=str2double(tmp);
if isnan(tmp)
    errordlg('Zadejte èíslo!');
else
    data.Fpl=abs(tmp);
end
set (hObject, 'String', data.Fpl);
setappdata(gcbf, 'vstupy', data);


function edit9_CreateFcn(hObject, eventdata, handles)
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


%zadavani mpl
function edit9_Callback(hObject, eventdata, handles)
data = getappdata(gcbf, 'vstupy');
tmp = get(handles.edit9, 'String');
tmp=str2double(tmp);
if isnan(tmp)
    errordlg('Zadejte èíslo!');
else
    data.mpl=abs(tmp);
end
set (hObject, 'String', data.mpl);
setappdata(gcbf, 'vstupy', data);


% provedeni vypoctu
function pushbutton1_Callback(hObject, eventdata, handles)
data=getappdata(gcbf, 'vstupy');
%nahrada skriptu zadejkonst
x=data.x; xpl=[data.xpl/2, data.xpl/2]; pocet_poli=1; delta=0.1; e30=0.00001; ke3=0.4;
sigma1=0; sigma2=0; mtd=data.mtd*data.ro; mnl=data.mnl*data.ro; mpl=data.mpl*data.ro;
Ftd=data.Ftd*1e3; Fnl=data.Fnl*1e3; Fpl=data.Fpl*1e3; konst_pruhyb=9.81*mtd/2/Ftd;
n=length(x)+1; ynl(1)=1.400; ynl(n)=1.400;
pridavak=get(handles.radiobutton1, 'value');
if pridavak==1
    xpl=[0,0];          %pocitame-li bez PL
end
%vypocet geometrie retezovky
vesaky;
axes(handles.axes2);
cla;
if pridavak~=1
    plot(xplnl, yplnl, 'r');    %vykresleni pridavaku      
end
hold on;
yves0=zeros(length(xves));
stem(xves, yves, '.');
stem(xves, yves0, '.');
plot(xnl, ynl);                 %vykresleni NL
plot([0,xnl(n)], [0,0]);        %vykresleni TD
axis ([0 xnl(n) -0.2 1.6]);
axis off;

%vypocet pruznosti vedeni
axes(handles.axes1);
konst;
ec=ec.*1000;                    %prevod na mm/N

%vypocet U
emax=ec(round(length(ec)/2));
emin=ec(1);
U=(emax-emin)/(emax+emin)*100;
set(handles.text22, 'string', num2str(emin,'%-5.2f'));
set(handles.text25, 'string', num2str(emax,'%-5.2f'));
set(handles.text30, 'string', num2str(U,'%-5.0f'));
set(handles.text13, 'String', num2str(sum(data.x),'%-5.1f'));

smaz=get(handles.checkbox2, 'value');
if smaz~=0
    cla;
    osy=[0 xnl(n) min(ec)-0.05 max(ec)+0.05];
else
    osy=axis;
    osy1=[0 xnl(n) min(ec)-0.05 max(ec)+0.05];
    if osy1(3)<osy(3)
        osy(3)=osy1(3);
    end
    if osy1(4)>osy(4)
        osy(4)=osy1(4);
    end
end
plot(lc, ec);                   %vykresleni pruznosti
axis (osy);
hold on;
ylabel('pruznost [mm/N]');
xlabel('delka [m]');
grid on;

%pocatecni inicializace a naplneni vzorovych vstupnich udaju
function initialize_gui(fig_data, handles) 
data.ro=0.0089;                       %merna vaha medi, kg/mm2*m
data.x = [3,7,7,7,7,7,7,3];           %edit1
data.xpl=12;                          %edit2
data.mtd=100;                         %edit6, prurez TD (mm2)
data.mnl=50;                          %edit7, prurez NL (mm2)
data.mpl=35;                          %edit9, prurez PL (mm2)
data.Ftd=10;                          %edit4, tah v TD [kN]
data.Fnl=10;                          %edit5, tah v NL [kN]
data.Fpl=2.5;                         %edit8,tah v PL [kN]
setappdata(fig_data, 'vstupy', data);

set(handles.edit1, 'String', num2str(data.x, '%-5.1f'));
set(handles.edit2, 'String', data.xpl);
set(handles.edit5, 'String', data.Fnl);
set(handles.edit4, 'String', data.Ftd);
set(handles.edit7, 'String', data.mnl);
set(handles.edit6, 'String', data.mtd);
set(handles.edit8, 'String', data.Fpl);
set(handles.edit9, 'String', data.mpl);
set(handles.checkbox2, 'value', 1);
axes(handles.axes2);
axis off;

function checkbox2_Callback(hObject, eventdata, handles)

