!***************************************************************
! LGS_0306AD2              / 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
Shape$= get_material_param(Pce,"SHAPE")
if !cmp(Shape$,"C") && !cmp(Shape$,"U") then exit

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

GeomP= 1
GeomL= 2

get_piece_localp(LP) Pce,"IP",2
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
vec_copy(X) Z
vec_cross_prod(Z) X,Y
set_joint_pos(This) JP,X,Y,Z

set RETURN "1"

#UPDATE_JOINT#


#JOINT_TEST#

!debug ./joint_test.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

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

# include connection.def

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

P= 1
X= 2
Y= 3
Z= 4
JP= 5
PP= 6
PX= 7
PY= 8
PZ= 9
D= 10

Mode= get_obj_param(Mac,"MODE")
HoleQty = 2
HoleSize$ = "13.1"

Hgt= get_section_param(Pce,"HEIGHT")
Width = get_section_param(Pce,"WIDTH")

get_origin_pos(This) JP,X,Y,Z
get_origin_pos(Pce) PP,PX,PY,PZ

vec_rev(D) PX
Ok= proj_to_piece(JP,D,JP,D,Pce,0,2)

del_joint_det(This)

if Mode == 0 || Mode == 2 then
  ! Outer Holes
  ! Offset = (Hgt-30-30)
  Offset = 176

  init_iterator(I) "",This,"CONNECTION_ROLEPARTS","H"
  Hole= next_item(I)
  if !Hole then
    Hole= new_feature("HOLE")
    if !Hole then exit
    connect(This) Hole,"H"
    add_sobj(Pce) Hole
    set_obj_param(Hole) "T","1"
  endif
  set_origin_pos(Hole) JP,PY,PZ,PX
  set_feat_param(Hole) "TYPE","CGX"
  set_obj_param(Hole) "SX",Offset
  set_obj_param(Hole) "QTYX",HoleQty 
  set_obj_param(Hole) "DIA",HoleSize$
  set_obj_param(Hole) "D",Width
endif

if Mode == 1 || Mode == 2 then
  ! Inner holes
  ! Offset = (Hgt-100-100)
  Offset = 50

  init_iterator(I) "",This,"CONNECTION_ROLEPARTS","H2"
  Hole= next_item(I)
  if !Hole then
    Hole= new_feature("HOLE")
    if !Hole then exit
    connect(This) Hole,"H2"
    add_sobj(Pce) Hole
    set_obj_param(Hole) "T","1"
  endif
  set_origin_pos(Hole) JP,PY,PZ,PX
  set_feat_param(Hole) "TYPE","CGX"
  set_obj_param(Hole) "SX",Offset
  set_obj_param(Hole) "QTYX",HoleQty 
  set_obj_param(Hole) "DIA",HoleSize$
  set_obj_param(Hole) "D",Width
endif

set RETURN "1"

#JOINT_DETAILING#
