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=550;
plot_w=600; plot_h=frame_h;
margin_x=15; margin_y=15;

defaultfont="arial";
axes_w=3*margin_x+frame_w+plot_w
axes_h=2*margin_y+frame_h

vcr=scf(100001);

vcr.background=-2;
vcr.figure_position=[400 100];
vcr.figure_name=gettext("Verificación secciones concreto flexión simple")
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 = 240;

// ordered list of labels
labels1 = ["fc (MPa)","B (mm)", "H (mm)", "fy (MPa)"];
// ordered list of default values
values1 = [25, 500, 600, 420];
// 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=["0" "0" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""]';
tmp2=["230" "-230" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""]';
tmp3=["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 100 250 347],"tooltipstring","Refuerzos","tag","refuerzos")

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


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

function verificacion()
    
    //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
    
    fcthis=findobj("tag", "fc (MPa)")
    fcthis=evstr(fcthis.string)
    disp(fcthis)
    bthis=findobj("tag", "B (mm)")
    bthis=evstr(bthis.string)
    disp(bthis)
    hthis=findobj("tag", "H (mm)");
    hthis=evstr(hthis.string)
    disp(hthis)
    fythis=findobj("tag", "fy (MPa)")
    fythis=evstr(fythis.string)
    disp(fythis)
    
    [Mn,c,Sigmac,Epsc,X,Fc,sigmastens,estens,sigmascompr,escompr,ruptura,aceroRes,npti]=MnRect(fcthis,bthis,hthis,fythis,tableRef,0.01,"yes")
    disp(aceroRes)
    
    FiMn=0.9*Mn/1000^2
    FiMn=round(100*FiMn)/100
    uicontrol(vcr,"Style","text","Position",[125 25 150 30],"string",string(FiMn)+" kNm","fontsize",15,"HorizontalAlignment","center");
    
endfunction

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











