clear

global margin_x margin_y;
global frame_w frame_h plot_w plot_h;
global tableRef
global Mn c Sigmac Epsc X Fc sigmastens estens sigmascompr escompr ruptura aceroRes npti



frame_w=300; frame_h=600;
frameYY_w=300;
frameZZ_w=300;
frameN_h=150;
plot_w=600; plot_h=frame_h;
margin_x=15; margin_y=15;

defaultfont="arial";
axes_w=4*margin_x+frame_w+frameYY_w+frameZZ_w
axes_h=2*margin_y+frame_h

vcr=scf(100001);

vcr.background=-2;
vcr.figure_position=[400 50];
vcr.figure_name=gettext("Verificación secciones concreto flexión")
vcr.axes_size=[axes_w axes_h]

//delmenu(vcr.figure_id,gettext("&File"))
delmenu(vcr.figure_id,gettext("&Tools"))
delmenu(vcr.figure_id,gettext("&Edit"))
delmenu(vcr.figure_id,gettext("&?"))
toolbar(vcr.figure_id,"off")

//h1= uimenu("parent",vcr,"label",gettext("File"));
h2= uimenu("parent",vcr,"label",gettext("About"));


uimenu("parent",vcr,"label",gettext("Close"),"callback","vcr=get_figure_handle(100001);delete(vcr)","tag","close_menu")
uimenu("parent",h2,"label",gettext("About"),"callback","vcr_About();");
function vcr_About()
    msg=msprintf(gettext("vcr es una programma de Daniele Tonelli."))
    messagebox(msg,gettext("About"),"info","modal")
endfunction

sleep(500)

my_frame = uicontrol("parent",vcr, "relief","groove","style","frame", "units","pixels","position",[margin_x margin_y frame_w frame_h],"horizontalalignment","center", "background",[1 1 1],"tag","frame_control");
my_frame_title = uicontrol("parent",vcr, "style","text","string","Sección rectangular","units","pixels","position",[30+margin_x margin_y+frame_h-10 frame_w-60 20],"fontname",defaultfont, "fontunits","points","fontsize",16, "horizontalalignment","center","background",[1 1 1], "tag","title_frame_control");

guih1 = frame_w;
guih1o = 290;

// ordered list of labels
labels1 = ["fc (MPa)","B (mm)", "H (mm)", "fy (MPa)", "P (kN)"];
// ordered list of default values
values1 = [25, 500, 600, 420, 0];
// positioning
l1 = 40; l2 = 100; l3 = 110;
for k=1:size(labels1,2)
uicontrol("parent",vcr, "style","text","string",labels1(k), "position",[l1,guih1-k*20+guih1o,l2,20],"horizontalalignment","left","fontsize",14,"background",[1 1 1]);
guientry1(k) = uicontrol("parent",vcr, "style","edit","string",string(values1(k)), "position",[l3,guih1-k*20+guih1o,180,20],"horizontalalignment","left", "fontsize",14,"background",[.9 .9 .9], "tag",labels1(k));
end


//guih2 = 360;
//guih2o = 80;
//labels2 = ["# ref. (-)"];
//values2 = ["2"];
//l1 = 40; l2 = 100; l3 = 110;
//for k=1:size(labels2,2)
//uicontrol("parent",vcr, "style","text","string",labels2(k), "position",[l1,guih2-k*20+guih2o,l2,20],"horizontalalignment","left", "fontsize",14,"background",[1 1 1]);
//guientry2(k) = uicontrol("parent",vcr, "style","edit","string",values2(k), "position",[l3,guih2-k*20+guih2o,180,20],"horizontalalignment","left", "fontsize",14,"background",[.9 .9 .9], "tag",labels2(k));
//end

//param=[]
//nref=findobj("tag","# ref. (-)");
//param.nref=evstr(nref.string);


// Include an editable table into a figure:
// Building a table of data:
params = [" " "x (mm)" "y (mm)" "As (mm²)" ];
refuerzos = ["n. 1" "n. 2" "n. 3" "n. 4" "n. 5" "n. 6" "n. 7" "n. 8" "n. 9" "n. 10" "n. 11" "n. 12" "n. 13" "n. 14" "n. 15" "n. 16" "n. 17" "n. 18" "n. 19" "n. 20"]';
tmp1=["-180" "180" "-180" "180" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""]';
tmp2=["230" "230" "-230" "-230" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""]';
tmp3=["540" "540" "540" "540" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""]';
tableRefInp = [params; [refuerzos tmp1 tmp2 tmp3]]

//f = gcf();
//clf
//as = f.axes_size;  // [width height]
ut = uicontrol("parent",vcr,"style","table","string",tableRefInp,"position",[40 130 250 347],"tooltipstring","Refuerzos","tag","refuerzos")

// Adding button
huibutton = uicontrol(vcr, "style","pushbutton","Position",[110 100 100 20], "String","Calcular","BackgroundColor",[.9 .9 .9], "fontsize",14,"Callback","verificacion");


//exec('englib-NSR-10.sci', -1)



uicontrol(vcr,"Style","text","Position",[40 55 35 30],"string","$\Phi =$","fontsize",12,"HorizontalAlignment","left");
uicontrol(vcr,"Style","text","Position",[40 25 35 30],"string","$\Phi =$","fontsize",12,"HorizontalAlignment","left");

uicontrol(vcr,"Style","text","Position",[130 55 70 30],"string","$\Phi M_\text{n,yy}=$","fontsize",12,"HorizontalAlignment","left");
uicontrol(vcr,"Style","text","Position",[130 25 70 30],"string","$\Phi M_\text{n,zz}=$","fontsize",12,"HorizontalAlignment","left");


marginFrame_x=10
marginFrame_y=10
marginFrameTop_y=35
tamanhoTexto=15
H_linea=22


my_frameYY = uicontrol("parent",vcr, "relief","groove","style","frame", "units","pixels","position",[2*margin_x+frame_w 2*margin_y+frameN_h frameYY_w frame_h-frameN_h-margin_y],"horizontalalignment","center", "background",[1 1 1],"tag","frameYY_results");
my_frameYY_title = uicontrol("parent",vcr, "style","text","string","Resultados y-y","units","pixels","position",[30+2*margin_x+frame_w margin_y+frame_h-10 frameYY_w-80 20],"fontname",defaultfont, "fontunits","points","fontsize",16, "horizontalalignment","center","background",[1 1 1], "tag","title_frameYY_results");

my_frameYY_h=my_frameYY.Position(1,4)


//uicontrol(my_frameYY,"Style","text","Position",[marginFrame_x my_frameYY_h-marginFrameTop_y 35 30],"string","$\Phi =$","fontsize",12,"HorizontalAlignment","left");
//uicontrol(my_frameYY,"Style","text","Position",[marginFrame_x my_frameYY_h-tamanhoTexto-margin_y-50-30 35 30],"string","$\Phi =$","fontsize",12,"HorizontalAlignment","left");



my_frameZZ = uicontrol("parent",vcr, "relief","groove","style","frame", "units","pixels","position",[3*margin_x+frame_w+frameYY_w 2*margin_y+frameN_h frameZZ_w frame_h-frameN_h-margin_y],"horizontalalignment","center", "background",[1 1 1],"tag","frameZZ_results");
my_frameZZ_title = uicontrol("parent",vcr, "style","text","string","Resultados z-z","units","pixels","position",[30+3*margin_x+frame_w+frameYY_w margin_y+frame_h-10 frameZZ_w-80 20],"fontname",defaultfont, "fontunits","points","fontsize",16, "horizontalalignment","center","background",[1 1 1], "tag","title_frameZZ_results");

my_frameN = uicontrol("parent",vcr, "relief","groove","style","frame", "units","pixels","position",[2*margin_x+frame_w margin_y frameYY_w frameN_h],"horizontalalignment","center", "background",[1 1 1],"tag","frameN_results");
my_frameN_title = uicontrol("parent",vcr, "style","text","string","Resultados Axiales","units","pixels","position",[30+2*margin_x+frame_w margin_y+frameN_h-10 frameYY_w-80 20],"fontname",defaultfont, "fontunits","points","fontsize",16, "horizontalalignment","center","background",[1 1 1], "tag","title_frameN_results");















function verificacion()
    
    exec('englib-NSR-10.sci', -1)
    
    //h=get(ut)
    
    tableRefInp=matrix(ut.string,size(tableRefInp))
    
    N=size(tableRefInp)
    N=N(1,1)
    
    for i=2:N
        if tableRefInp(i,2) ~= ""
            tableRef(i-1,1)=evstr(tableRefInp(i,2))
            tableRef(i-1,2)=evstr(tableRefInp(i,3))
            tableRef(i-1,3)=evstr(tableRefInp(i,4))
        end
    end
    
    fc=findobj("tag", "fc (MPa)")
    fc=evstr(fc.string)
    b=findobj("tag", "B (mm)")
    b=evstr(b.string)
    h=findobj("tag", "H (mm)");
    h=evstr(h.string)
    fy=findobj("tag", "fy (MPa)")
    fy=evstr(fy.string)
    P=findobj("tag", "P (kN)")
    P=evstr(P.string)
    P=1000*P
    
    [Mnyy,cyy,Sigmacyy,Epscyy,Xyy,Fcyy,sigmastensyy,estensyy,sigmascompryy,escompryy,rupturayy,aceroResyy,dyy,nptiyy,DeltaPyy]=MnRect(fc,b,h,fy,tableRef,P,.01,0.001,'yes')
    Fiyy=Fi(estensyy)
    //Fiyy=round(100*Fiyy)/100
    
    FiMnyy=Fiyy*Mnyy/1000^2
    FiMnyy=round(100*FiMnyy)/100
    uicontrol(vcr,"Style","text","Position",[75 55 35 30],"string",string(Fiyy),"fontsize",12,"HorizontalAlignment","left");
    if abs(estensyy)<=0.004 then
        uicontrol(vcr,"Style","text","Position",[105 55 20 30],"string","!","fontsize",12,"HorizontalAlignment","center","BackgroundColor",[1 .8 0]);
    end
    uicontrol(vcr,"Style","text","Position",[200 55 90 30],"string",string(FiMnyy)+" kNm","fontsize",12,"HorizontalAlignment","center");
    
    tableRefzz(:,1)=tableRef(:,2)
    tableRefzz(:,2)=tableRef(:,1)
    tableRefzz(:,3)=tableRef(:,3)
    
    [Mnzz,czz,Sigmaczz,Epsczz,Xzz,Fczz,sigmastenszz,estenszz,sigmascomprzz,escomprzz,rupturazz,aceroReszz,dzz,nptizz,DeltaPzz]=MnRect(fc,h,b,fy,tableRefzz,P,.01,0.001,'yes')
    Fizz=Fi(estenszz)
    Fizz=round(100*Fizz)/100
    
    FiMnzz=Fizz*Mnzz/1000^2
    FiMnzz=round(100*FiMnzz)/100
    uicontrol(vcr,"Style","text","Position",[75 25 35 30],"string",string(Fizz),"fontsize",12,"HorizontalAlignment","left");
    if abs(estenszz)<=0.004 then
        uicontrol(vcr,"Style","text","Position",[105 25 20 30],"string","!","fontsize",12,"HorizontalAlignment","center","BackgroundColor",[1 .8 0]);
    end
    uicontrol(vcr,"Style","text","Position",[200 25 90 30],"string",string(FiMnzz)+" kNm","fontsize",12,"HorizontalAlignment","center");
    
    uicontrol(my_frameYY,"Style","text","Position",[marginFrame_x my_frameYY_h-marginFrameTop_y 250 H_linea],"string",string(rupturayy(1,1)),"fontsize",tamanhoTexto,"HorizontalAlignment","left","background",[1 1 1]);
    uicontrol(my_frameYY,"Style","text","Position",[marginFrame_x my_frameYY_h-marginFrameTop_y-H_linea 250 H_linea],"string","Eje neutro, c = "+string(round(100*cyy)/100)+" mm","fontsize",tamanhoTexto,"HorizontalAlignment","left","background",[1 1 1]);
    uicontrol(my_frameYY,"Style","text","Position",[marginFrame_x my_frameYY_h-marginFrameTop_y-2*H_linea 250 H_linea],"string","Altura efectiva, d = "+string(round(100*dyy)/100)+" mm","fontsize",tamanhoTexto,"HorizontalAlignment","left","background",[1 1 1]);
    uicontrol(my_frameYY,"Style","text","Position",[marginFrame_x my_frameYY_h-marginFrameTop_y-3*H_linea 250 H_linea],"string","ε tens = "+string(round(10000*estensyy)/10000)+"       →   "+"Φ = "+string(Fiyy),"fontsize",tamanhoTexto,"HorizontalAlignment","left","background",[1 1 1]);
    
    
endfunction


