!***************************************************************
! LGS_0306J              / 2006-03-15   / Vertex Systems
!***************************************************************
!
#UPDATE_JOINT#

!debug ./update_joint.dbg

I= new_iterator("",0,"ROLED","THIS")
This = next_item(I)
if !This then exit
init_iterator(I) "",This,"CONNECTION_ROLEPARTS","PCE"
Pce= next_item(I)
if !Pce then exit
init_iterator(I) "",This,"CONNECTION_ROLEPARTS","MAC"
Mac= next_item(I)
if !Mac then exit

!Check material
Mat$= get_material_param(Pce,"SHAPE")
if !cmp(Mat$,"C") and !cmp(Mat$,"U") then exit

P= 1
X= 2
Y= 3
Z= 4
LP= 5
JP= 6
D = 7

GeomP= 1
GeomL= 2

Ndepth= mm_to_dwg(3) 

get_piece_localp(LP) Pce,"IP",5
get_piece_vxgeom(GeomP) Pce,LP
Len= get_macro_param(Mac,"LENGTH")
get_origin_pos(Mac) P,X,Y,Z
vec_times_scalar(X) X,Len
vec_add(X) X,P
new_vxgeom(GeomL) "LINE",P,X
if !vxgeom_cross_pnts(GeomL,P,GeomP,JP) then exit
vec_sub(Z) P,JP
Dist= vec_len(Z)
CrDist= get_section_param(Pce,"HEIGHT") * 0.52
if (Dist > CrDist) then exit
if !is_in_vxgeom(GeomL,P,1,mm_to_dwg(0.001)) then exit

get_origin_pos(Pce) P,X,Y,Z,JP
set_joint_pos(This) JP,X,Y,Z

set RETURN "1"

#UPDATE_JOINT#


#JOINT_TEST#

I= new_iterator("",0,"ROLED","THIS")
This = next_item(I)
if !This then exit
init_iterator(I) "",This,"CONNECTION_ROLEPARTS","PCE"
Pce= next_item(I)
if !Pce then exit

get_joint_pnt(1) This
get_vxgeom(1) Pce
point_to_vxgeom(1) 1,1
if (is_in_vxgeom(1,1,1,mm_to_dwg(0.1)) < 1) then exit
set RETURN "1"

#JOINT_TEST#


#JOINT_DETAILING#

!debug ./joint_detailing.dbg

Depth= mm_to_dwg(5)
Depth$= Depth

I= new_iterator("",0,"ROLED","THIS")
This = next_item(I)
if !This then exit
init_iterator(I) "",This,"CONNECTION_ROLEPARTS","PCE"
Pce= next_item(I)
if !Pce then exit
DimP= get_section_param(Pce,"HEIGHT")
DimP$ = DimP
init_iterator(I) "",This,"CONNECTION_ROLEPARTS","MAC"
Mac= next_item(I)
if !Mac then exit
Size$= get_obj_param(Mac,"SIZE")

P= 1
X= 2
Y= 3
Z= 4
D = 5

init_iterator(I) "",This,"CONNECTION_ROLEPARTS","M1"
Hole= next_item(I)
if !Hole then
  Hole = new_feature("DIMPLE",0,0,"dimple_male.vxm","1+2+4","1")
  if !Hole then exit
  connect(This) Hole,"M1"
  add_sobj(Pce) Hole
  if (!empty_string(Size$)) then
    set_obj_param(Hole) "DIMX",Size$
    set_obj_param(Hole) "DIMY",Size$
    set_obj_param(Hole) "DIMX",Size$,3
    set_obj_param(Hole) "DIMY",Size$,3
  endif
endif

get_origin_pos(This) P,X,Y,Z

vec_copy(D) Y
if !proj_to_piece(P,X,P,D,Pce,0.0,0) then exit
vec_cross_prod(X) Y,Z
set_origin_pos(Hole) P,Z,X,D

init_iterator(I) "",This,"CONNECTION_ROLEPARTS","M2"
Hole= next_item(I)
if !Hole then
  Hole = new_feature("DIMPLE",0,0,"dimple_male.vxm","1+2+4","1")
  if !Hole then exit
  connect(This) Hole,"M2"
  add_sobj(Pce) Hole
  if (!empty_string(Size$)) then
    set_obj_param(Hole) "DIMX",Size$
    set_obj_param(Hole) "DIMY",Size$
    set_obj_param(Hole) "DIMX",Size$,3
    set_obj_param(Hole) "DIMY",Size$,3
  endif
endif

get_origin_pos(This) P,X,Y,Z

vec_rev(D) Y
if !proj_to_piece(P,X,P,D,Pce,0.0,0) then exit
vec_cross_prod(X) Y,Z
set_origin_pos(Hole) P,Z,X,D

set RETURN "1"

#JOINT_DETAILING#
