!***************************************************************
! LGS_0325B             / 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") and !cmp(Mat$,"S") then exit

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

GeomP= 1
GeomL= 2

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,Y,Z,X

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

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

File$= get_obj_param(This,"FILE")
Dia1= get_obj_param(This,"DIA1")
Dia2= get_obj_param(This,"DIA2")
Dist1= get_obj_param(This,"DIST1")
Dist2= get_obj_param(This,"DIST2")

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

PceHeight= get_section_param(Pce,"HEIGHT")
PceWidth= get_section_param(Pce,"WIDTH")

init_iterator(I) "",This,"CONNECTION_ROLEPARTS","MAC"
Mac= next_item(I)
if !Mac then exit

JP= 1
JX= 2
JY= 3
JZ= 4
PP = 5
PX = 6
PY = 7
PZ = 8
D= 9
PN = 10

get_origin_pos(This) JP,JX,JY,JZ
get_origin_pos(Pce) PP,PX,PY,PZ

init_iterator(I) "",This,"CONNECTION_ROLEPARTS","P"
Punch= next_item(I)
if (!Punch) then
  Punch=new_feature("MODSUB",0,"0",File$,"1+2",File$)
  add_sobj(Pce) Punch
  connect(This) Punch,"P"
endif

vec_rev(D) PY
Ok= proj_to_piece(JP,PN,JP,D,Pce,0,0)

vec_rev(D) JY
set_origin_pos(Punch) JP,D,JZ,JX
if Dia1 > 0 then
  set_obj_param(Punch) "DIA1",Dia1,1+2
endif
if Dia2 > 0 then
  set_obj_param(Punch) "DIA2",Dia2,1+2
endif
if Dist1 > 0 then
  set_obj_param(Punch) "DIST1",Dist1,1+2
endif
if Dist2 > 0 then
  set_obj_param(Punch) "DIST2",Dist2,1+2
endif
set_obj_param(Punch) "PCE_HEIGHT",PceHeight,1+2
set_obj_param(Punch) "PCE_WIDTH",PceWidth,1+2

init_iterator(I) "",This,"CONNECTION_ROLEPARTS","P2"
Punch= next_item(I)
if (!Punch) then
  Punch=new_feature("MODSUB",0,"0",File$,"1+2",File$)
  add_sobj(Pce) Punch
  connect(This) Punch,"P2"
endif

vec_copy(D) PY
Ok= proj_to_piece(JP,PN,JP,D,Pce,0,0)

vec_rev(D) JX
set_origin_pos(Punch) JP,JY,JZ,D
if Dia1 > 0 then
  set_obj_param(Punch) "DIA1",Dia1,1+2
endif
if Dia2 > 0 then
  set_obj_param(Punch) "DIA2",Dia2,1+2
endif
if Dist1 > 0 then
  set_obj_param(Punch) "DIST1",Dist1,1+2
endif
if Dist2 > 0 then
  set_obj_param(Punch) "DIST2",Dist2,1+2
endif
set_obj_param(Punch) "PCE_HEIGHT",PceHeight,1+2
set_obj_param(Punch) "PCE_WIDTH",PceWidth,1+2

set RETURN "1"

#JOINT_DETAILING#