You are on page 1of 9

GLOBAL WIDGET spr_id,but_file

GLOBAL STRING file_name[256]


/******************************* CLASS user_pcl *****************************/
CLASS user_pcl
CLASSWIDE WIDGET form_id,frame_id,dbox_id,box_nd1,frame_id1,cm_id,slide_id,b1,b2
CLASSWIDE WIDGET list_rc,dbox_id1,toggle_id,toggle_id1,menubar_id,usermenu_id
FUNCTION init()
INTEGER my_data
GLOBAL WIDGET but_file
menubar_id=uil_primary.get_menubar_id()
usermenu_id=ui_menu_create(menubar_id,"menu_call","Programms")
form_id=ui_form_create("",10.6,1.5,"UL",2.7,8.1,"Elm_H_inspection","")
ui_item_create(usermenu_id,"my_item","H - verify...",FALSE)
list_rc=ui_listbox_create(form_id,"sel_item",0.1,0.1,2.5,12,"Existing groups set:","SINGLE",TRUE)
dbox_id=ui_databox_create(form_id,"",0.1,3.,0.,0.8,"Critical element size:",10.0,FALSE,"REAL",1)
cm_id=ui_colormenu_create(form_id,"small_cl",1.9,3.5,0.7,0.2,"Small Elements
Color:","Left",1.,1.,3,my_data)
frame_id=ui_selectframe_create(form_id,"",0.1,4.,2.5,0.8,"",TRUE)
box_nd1=ui_selectdatabox_create(frame_id,"select_elms",0.1,0.1,0.,2.2,"Select elements:","", @
TRUE,"ELEMENT","Cursor")
frame_id1=ui_selectframe_create(form_id,"",0.1,5.,2.5,1.1,"",TRUE)
toggle_id1=ui_toggle_create(frame_id1,"switch2",0.1,0.1,"Group utility")
dbox_id1=ui_databox_create(frame_id1,"",0.1,0.48,0.,2.2,"Small elms Group
Name:","Small_elms",TRUE,"STRING",1)
ui_wid_set(dbox_id1,"ENABLE",FALSE)
toggle_id=ui_toggle_create(form_id,"",0.1,6.2,"Table message")
but_file=ui_toggle_create(form_id,"file_sh",0.1,6.6,"Print To File...")
b1=ui_button_create(form_id,"apply",0.2,7.7,1.0,0.0,"Apply",TRUE,FALSE)
b2=ui_button_create(form_id,"cancel",1.6,7.7,1.0,0.0,"Cancel",TRUE,FALSE)
slide_id=ui_slidebar_create(form_id,"",0.05,7.,2.6,"Percentage of Elements
count",0.,0,TRUE,"0","100",TRUE,0.,100.)
ui_wid_set(slide_id,"DISPLAY",FALSE)
END FUNCTION
/* -------------------------------------------- menu_call: ----------------------------------------------- */
FUNCTION menu_call(item_name)
STRING item_name[],db_file_name[64]

INTEGER opened_db
GLOBAL INTEGER s_el_colr
opened_db=db_name_get(db_file_name)
IF(opened_db!=0) THEN
user_message("Warn",3,"USER_PCL","*** Error Open Database ***")
ui_form_hide("user_pcl")
RETURN(1)
END IF
IF(item_name == "my_item") THEN
s_el_colr=8
ui_wid_set(cm_id,"COLOR",s_el_colr)
GLOBAL STRING groups[32](VIRTUAL)
GLOBAL INTEGER ngroups
ui_listbox_items_delete(list_rc)
ga_group_ngroups_get(ngroups)
/* Get groups number
*/
SYS_ALLOCATE_ARRAY(groups,1,(ngroups+1))
ga_group_groups_get(groups)
/* Get string of group names */
ui_listbox_items_create(list_rc,groups,groups,ngroups,WIDGET_NULL)
ui_form_display("user_pcl")
END IF
END FUNCTION
/* ------------------------------------------------- switch: --------------------------------------------- */
FUNCTION switch2(sr2)
LOGICAL sr2
IF(!sr2) THEN
ui_wid_set(dbox_id1,"ENABLE",FALSE)
ELSE
ui_wid_set(dbox_id1,"ENABLE",TRUE)
END IF
END FUNCTION
/* ------------------------------------------------ file_sh: -------------------------------------------- */
FUNCTION file_sh(answ)
LOGICAL answ
GLOBAL INTEGER prf
GLOBAL WIDGET but_file
prf=0
ui_wid_get(but_file,"VALUE",answ)
IF(answ==TRUE) THEN
user_pcl_3.init3()
prf=1
END IF
END FUNCTION
/* ------------------------------------------ small_cl: ------------------------------------------------- */
FUNCTION small_cl(id_colorbar,my_data,new_color)

WIDGET id_colorbar
INTEGER new_color,my_data
GLOBAL INTEGER s_el_colr
s_el_colr=new_color
END FUNCTION
/* ------------------------------------------ sel_item: ------------------------------------------------- */
FUNCTION sel_item(n_i,l_i)
STRING l_i[]()
INTEGER n_i
ui_wid_set(dbox_id1,"VALUE",l_i) /* The widget parametr manipulation */
END FUNCTION
/* ------------------------------------------- select_elms: --------------------------------------------- */
FUNCTION select_elms(sel_data)
STRING sel_data[]
STRING sdbox_string[VIRTUAL]
GLOBAL INTEGER status,nelms,elms(VIRTUAL)
IF(sel_data=="VALUE_CHANGED") THEN
ui_wid_get_vstring(box_nd1,"VALUE",sdbox_string)
/* Put value of widget string in virtual
string */
sdbox_string=str_strip_lead(sdbox_string)
nelms=app_count_id_list(1024,sdbox_string,FALSE,status) /* 1024 - from p.4.6.1 - "File
Ipensums.i" */
IF(status != 0) THEN RETURN status
/* Termination, (see p2.6.2, Structure PSL
Function */
status=SYS_ALLOCATE_ARRAY(elms,1,nelms)
/* Allocation 1-Dimensional array
elms(nelms)*/
fem_u_get_id_list(1024,sdbox_string,nelms,TRUE,elms(1:))
from #1 */
END IF
END FUNCTION

/* (1:) - All elements, begin

/* ------------------------------------------------- Apply: --------------------------------------------- */


FUNCTION apply
GLOBAL WIDGET spr_id,form_id1
GLOBAL INTEGER nelms,elms(VIRTUAL),ngroups,prf,s_el_colr
GLOBAL STRING groups[32](VIRTUAL),file_name[256]
STRING dbox_string[VIRTUAL],str_elm[48],s_elm[7],s_e_code[7],lab[6],str_file[120]
INTEGER i,j,l,k,nodes(8),elm(1),code(1),row,ne
/* (8) - for solids element */
INTEGER ref(8),analys(8),n_small,flag,chan
REAL xyz(8,3),rang,sl,sm,sn,s1,s2,s3,d,d_m,slbar_step,dsn
LOGICAL ans,ans1
/* declaration for material name reading: */
REAL t(3),t2(6)
INTEGER t1(64),m,pid
STRING mat[32],prop_name[32]
/* declaration for small elements frame visualization: */

REAL p1(3),p2(3)
GLOBAL INTEGER seg_id,nn
IF(seg_id!=0) THEN
gm_segment_delete(seg_id)
END IF
gm_segment_create(seg_id)
display_cleanup()

/* Segment for small elements visualization


/* Clean PATRAN-red color of selected elements

*/
*/

ui_wid_get(dbox_id,"VALUE",rang)
ui_wid_get(toggle_id1,"VALUE",ans)
/* New group creation (if it not exists yet):
IF(ans==TRUE) THEN
ui_wid_get_vstring(dbox_id1,"VALUE",dbox_string)
dbox_string=str_strip_lead(dbox_string)
if(dbox_string=="kev") then
ui_writec("kopanev")
end if
l=0
FOR(i=1 TO ngroups)
IF(groups(i)==dbox_string) THEN
l=1
END IF
END FOR
IF(l!=1) THEN
ga_group_create(dbox_string)
groups(ngroups+1)=dbox_string
ngroups=ngroups+1
SYS_REALLOCATE_ARRAY(groups,1,(ngroups+1))
STRING new_gr_name[32](1)
new_gr_name(1)=dbox_string
ui_listbox_items_create(list_rc,groups,new_gr_name,1,WIDGET_NULL)
END IF
END IF

IF(nelms>200) THEN
ui_wid_set(b1,"DISPLAY",FALSE)
ui_wid_set(b2,"DISPLAY",FALSE)
lab=str_from_integer(nelms)
ui_wid_set(slide_id,"MAXLABEL",lab)
ui_wid_set(slide_id,"DISPLAY",TRUE)
END IF
dsn=0.
/* ------------- Small Elements Foundation: ------------- */
row=1
n_small=0
d_m=1.e6
FOR(i=1 TO nelms)
IF(nelms>200) THEN

*/

slbar_step=i*100./nelms
IF((slbar_step-dsn) >= 1.) THEN
ui_wid_set(slide_id,"VALUE",slbar_step)
ui_wid_set(slide_id,"DISPLAY",TRUE)
em_synchronize()
dsn=slbar_step
END IF
END IF
flag=0
elm(1)=elms(i)
db_get_elem_etop(1,elm,code)
db_get_nodes_for_elems(1,code(1),elm,nodes)
db_get_nodes(code(1),nodes,ref,analys,xyz)
FOR(j=1 TO code(1))
IF(j<code(1)) THEN
l=j+1
ELSE
l=1
END IF

/* Get element's code


*/
/* Numbers of element's nodes
*/
/* Coordinates of element's nodes */

/* j - number of first node (P1) from array xyz() */


/* l - number of second node (P2) from array xyz() */

sl=xyz(l,1)-xyz(j,1)
sm=xyz(l,2)-xyz(j,2)
sn=xyz(l,3)-xyz(j,3)
FOR(k=1 TO code(1))
IF(k!=j && k!=l) THEN
s1=(xyz(k,1)-xyz(j,1))*sm - (xyz(k,2)-xyz(j,2))*sl
s1=s1*s1
s2=(xyz(k,2)-xyz(j,2))*sn - (xyz(k,3)-xyz(j,3))*sm
s2=s2*s2
s3=(xyz(k,3)-xyz(j,3))*sl - (xyz(k,1)-xyz(j,1))*sn
s3=s3*s3
d=(s1+s2+s3)/(sl*sl+sm*sm+sn*sn)
d=mth_sqrt(d)
IF(d<d_m) THEN
d_m=d
END IF
END IF
END FOR
END FOR
IF(d_m<rang) THEN
str_formatc(str_elm,"Elm %d",elm(1))
flag=1
IF(ans==TRUE) THEN
ga_group_entity_add(dbox_string,str_elm)
END IF
END IF
IF(flag==1) THEN

/* Adding this small element to group */

n_small=n_small+1
ne=elm(1)
IF(code(1)==4) THEN
s_e_code="quad4"
END IF
IF(code(1)==3) THEN
s_e_code="tria3"
END IF
m=0
db_element(ne,k,k,k,pid,k,t,t1,t2,k,k,k)
/* get pid - Properties_ID */
db_get_region_definition(pid,prop_name,k,k,k,k,k,k,k,m,k,k) /* get m - Material_ID and
prop_name */
db_get_material(m,mat,k,k,k,str_elm,k,k)
/* get mat - Material_name */
IF(m==0) THEN
prop_name="--"
mat="--"
END IF
END IF
IF(n_small==1) THEN
ui_wid_get(toggle_id,"VALUE",ans1)
IF(ans1==TRUE) THEN
user_pcl_2.init2()
END IF
END IF

/*------------- Table Message: --------------*/

IF(spr_id!=WIDGET_NULL) THEN
/* IF WIDGET spr_id exist, then... */
IF(flag==1) THEN
/* IF element is small, then... */
s_elm=str_from_integer(ne)
IF(row>1) THEN
ui_spread_row_create(spr_id,"") /* If deal of strings in table not inought - Add new string */
END IF
ui_spread_set_cell(spr_id,1,row,1,s_elm) /* Collumn #1 (i - Element's Number)
*/
ui_spread_set_cell(spr_id,2,row,1,s_e_code) /* Collumn #2 (Element's code)
s_elm=str_from_real(d_m)
ui_spread_set_cell(spr_id,3,row,1,s_elm)

*/

/* Collumn #3 (Minimal Height of Element) */

ui_spread_set_cell(spr_id,4,row,1,prop_name) /* Collumn #4 (Properties Name of Element) */


ui_spread_set_cell(spr_id,5,row,1,mat)

/* Collumn #5 (Material of Element)

row=row+1
END IF
END IF
/* Table has created */

IF(prf==1) THEN
/* ----------- Print to file: ------------------*/
IF(n_small==1) THEN
text_open(file_name,"NOW",0,0,chan)
str_file=" Elm_ID Code Height
Properties
Material"

*/

text_write_string(chan,str_file)
END IF
IF(flag==1) THEN
str_formatc(str_file," %6d %6s
text_write_string(chan,str_file)
END IF
END IF

%4.1f

%-32s

%s",ne,s_e_code,d_m,prop_name,mat)

IF(flag==1) THEN
/* ----------- Small elements frame visualization: ------------------*/
FOR(j=1 TO code(1))
/* j - number of first node (P1) from array xyz() */
IF(j<code) THEN
l=j+1
/* l - number of second node (P2) from array xyz() */
ELSE
l=1
END IF
FOR(nn=1 TO 3)
p1(nn)=xyz(j,nn)
p2(nn)=xyz(l,nn)
END FOR
gm_draw_line(seg_id,s_el_colr,p1,p2)
END FOR
END IF
d_m=1.e6
END FOR /* Elements Number */
ui_writec("**** %d Small Elements found ****",n_small)
text_close(chan,"")
gm_segment_flush() /* Display all created segments */
IF(ans1==TRUE) THEN
ui_wid_set(form_id1,"DISPLAY",TRUE)
END IF

/* Display Table */

ui_wid_set(b1,"DISPLAY",TRUE)
ui_wid_set(b2,"DISPLAY",TRUE)
ui_wid_set(slide_id,"DISPLAY",FALSE)
END FUNCTION
/* ------------------------------------ Cancel CLASS user_pcl ------------------------------------------ */
FUNCTION cancel
GLOBAL INTEGER seg_id
gm_segment_delete(seg_id)
ui_form_hide("user_pcl")
END FUNCTION
END CLASS
/*************************************** Next CLASS (for table):
******************************************/

CLASS user_pcl_2
$CLASSWIDE WIDGET form_id1
FUNCTION init2()
GLOBAL WIDGET spr_id,form_id1
STRING lcoll[12](5),lrow[1](1)
INTEGER i
form_id1=ui_form_create("",.1,7.5,"UL",7.5,2.5,"Small Elements Table","")
ui_wid_set(form_id1,"DISPLAY",FALSE)
ui_button_create(form_id1,"cancel",6.7,0.5,0.8,0.0,"Cancel",TRUE,FALSE)
spr_id=ui_spread_create(form_id1,"",0.1,0.05,6.4,2.35,0.,5,5,1,1,lcoll,lrow,"","","","READONLY")
lcoll(1)="Element's ID"
lcoll(2)="Code"
lcoll(3)="H_min"
lcoll(4)="Properties"
lcoll(5)="Material"
FOR(i=1 TO 5)
ui_spread_set_label(spr_id,1,i,1,lcoll(i))
END FOR
END FUNCTION
/* --------------- Cancel CLASS user_pcl_2 ------------------ */
FUNCTION cancel
GLOBAL WIDGET spr_id
ui_form_delete("user_pcl_2")
spr_id=WIDGET_NULL
/* NULL for WIDGET-ID */
END FUNCTION
END CLASS
/********************************** Next CLASS (for print-file):
******************************************/
CLASS user_pcl_3
CLASSWIDE WIDGET form_id2,file_cr
FUNCTION init3()
GLOBAL STRING file_name[256]
form_id2=ui_form_create("",2.5,3.5,"UL",5.2,4.1,"Print To File","")
file_cr=ui_file_create(
@
form_id2,
@
"open_file",
@
0.1,
@
0.1,
@
5.0,
@
7,
@

"Filter",
@
"*.hmsg",
@
"Directories",
@
"File List",
@
"Create New File",
@
file_name,
@
"OK",
@
"Filter",
@
"Cancel")
IF(file_cr == WIDGET_NULL) THEN
ui_writec("*************NULL file_cr***************")
END IF
ui_form_display("user_pcl_3")
END FUNCTION
/*--------------------------------------- OPEN_FILE ------------------------------------------*/
FUNCTION open_file(name,sel_but)
STRING name[],sel_but[]
GLOBAL STRING file_name[256]
GLOBAL WIDGET but_file
IF(sel_but == "CANCEL") THEN
ui_form_delete("user_pcl_3")
ui_wid_set(but_file,"VALUE",FALSE)
ELSE
str_formatc(file_name,"%s.hmsg",name)
ui_form_delete("user_pcl_3")
END IF
END FUNCTION
END CLASS