!   TITLE:  tv_cir_bore.mac (SM_TOOL)
!
!
!
!   This sub-macro is used to create a circular cylinder shaped volume
!   which is to be subtracted out, thereby creating a cylindrical
!   shaped cavity in the selected volume. This volume may be a right
!   circular cylinder (phibev = 0), or an angled (0 < phibev < 90) conic
!   section.
!
!   Parameters needed to be passed to this macro are:
!
!       A selected volume
!
!       opt = input options: 1,2,3,4,5 and 6
!
!       p1 = c.s. origin keypoint
!       p2 = c.s. +x axis keypoint
!       p3 = c.s. +y axis keypoint
!
!       xcutc = x component of cut volume local c.s.
!       ycutc = y component of cut volume local c.s.
!       zcutc = z component of cut volume local c.s.
!       rotxyc = 1st orientation angle (+x to +y) of 'reccutcs' c.s.
!       rotyzc = 2nd orientation angle (+y to +z) of 'reccutcs' c.s.
!       rotzxc = 3rd orientation angle (+z to +x) of 'reccutcs' c.s.
!
!       dcut = the depth or thickness of the volume
!       phibev = angle of bevel as measured from the normal
!            to the circular surfaces (from volume cut
!            coordinate system z axis)
!       acs1= pre-existing Active Coordinate System
!       dia_cut = diameter of cut/volume (along local c.s. x axis) on
!             penetrating surface
!
!   The position and orientation of the volume cut c.s. is measured in
!   relation to the active c.s. for options 1 and 4 (See below). From
!   this c.s., the local coordinate system building this volume is placed.
!   Options 2 and 5 allow construction of the cut volume from a c.s. de-
!   fined by 3 KP's. Lastly, options 3 and 6 allow construction from
!   a pre-existing c.s.  Options 4 thru 6 correspond to the same input as
!   1 thru 3, except that these options are used when the dimensions of the
!   base circle are specified.
!
!
!   The 6 options of input data are summarized as follows:
!
!       1.  Create local c.s. by CLOCAL, input:
!               xcutc, ycutc, zcutc, rotxyc, rotyzc, rotzxc
!
!           Dimensions of circle at the surface, input:
!               dia_cut
!
!       2.  Create local c.s. by CSKP, input:
!               p1, p2, p3
!
!           Dimensions of circle at the surface, input:
!               dia_cut
!
!       3.  Use pre-existing c.s., input: acs1
!
!           Dimensions of circle at the surface, input:
!               dia_cut
!
!       4.  Create local c.s. by CLOCAL, input:
!               xcutc, ycutc, zcutc, rotxyc, rotyzc, rotzxc
!
!           Dimensions of circle at the base, input:
!               dia_cut
!
!       5.  Create local c.s. by CSKP, input:
!               p1, p2, p3
!
!           Dimensions of circle at the base, input:
!               dia_cut
!
!       6.  Use pre-existing c.s., input: acs1
!
!           Dimensions of circle at the base, input:
!               dia_cut
!
!
! CIR_BORE,opt,xcutc,ycutc,zcutc,rotxyc,rotyzc,rotzxc,dia_cut,dcut,phibev
!
!
! CIR_BORE,opt,p1,p2,p3,dia_cut,dcut,phibev
!
!
! CIR_BORE,opt,acs1,dia_cut,dcut,phibev
!
!
*get,prkey_,active,0,prkey
/nopr

*get,_acs_,active,,csys
!
cm,v2bcut,volu      ! selected volume to be (2b) cut
!
*ask,opt,OPTION,1
!
!
*if,opt,eq,1,then
    *ask,xcutc,X coordinate of C.S.,0
    *ask,ycutc,Y coordinate of C.S.,0
    *ask,zcutc,Z coordinate of C.S.,0
    !
    *ask,rotxyc,XY rotation of C.S.,0
    *ask,rotyzc,YZ rotation of C.S.,0
    *ask,rotzxc,ZX rotation of C.S.,0
    !
    *ask,dia_cut,Surface Diameter,1
    *ask,dcut_,depth of cut,0.25
    *ask,phibev,bevel angle,0
    !
    x=dcut_*tan(phibev*rconv)
*endif
!
*if,opt,eq,2,then
    *ask,p1,origin KP of C.S.,0
    *ask,p2,+X axis KP of C.S.,0
    *ask,p3,+Y axis KP of C.S.,0
    !
    *ask,dia_cut,Surface Diameter,1
    *ask,dcut_,depth of cut,0.25
    *ask,phibev,bevel angle,0
    !
    x=dcut_*tan(phibev*rconv)
*endif
!
*if,opt,eq,3,then
    *ask,acs1,Active C.S.,0
    !
    *ask,dia_cut,Surface Diameter,1
    *ask,dcut_,depth of cut,0.25
    *ask,phibev,bevel angle,0
    !
    x=dcut_*tan(phibev*rconv)
*endif
!
*if,opt,eq,4,then
    *ask,xcutc,X coordinate of C.S.,0
    *ask,ycutc,Y coordinate of C.S.,0
    *ask,zcutc,Z coordinate of C.S.,0
    !
    *ask,rotxyc,XY rotation of C.S.,0
    *ask,rotyzc,YZ rotation of C.S.,0
    *ask,rotzxc,ZX rotation of C.S.,0
    !
    *ask,dia_cut,Base Diameter,1
    *ask,dcut_,depth of cut,0.25
    *ask,phibev,bevel angle,0
    !
    x=dcut_*tan(phibev*rconv)
    !
    dia_cut=dia_cut+2*x
*endif
!
*if,opt,eq,5,then
    *ask,p1,origin KP of C.S.,0
    *ask,p2,+X axis KP of C.S.,0
    *ask,p3,+Y axis KP of C.S.,0
    !
    *ask,dia_cut,Base Diameter,1
    *ask,dcut_,depth of cut,0.25
    *ask,phibev,bevel angle,0
    !
    x=dcut_*tan(phibev*rconv)
    !
    dia_cut=dia_cut+2*x
*endif
!
*if,opt,eq,6,then
    *ask,acs1,Active C.S.,0
    !
    *ask,dia_cut,Base Diameter,1
    *ask,dcut_,depth of cut,0.25
    *ask,phibev,bevel angle,0
    !
    x=dcut_*tan(phibev*rconv)
    !
    dia_cut=dia_cut+2*x
*endif
!
!
*if,opt,eq,1,then
    create_cs,0,'circutcs',1,xcutc,ycutc,zcutc,rotxyc,rotyzc,rotzxc
*endif
!
*if,opt,eq,2,then
    create_cs,1,'circutcs',1,p1,p2,p3
*endif
!
*if,opt,eq,3,then
    csys,acs1
*endif
!
*if,opt,eq,4,then
    create_cs,0,'circutcs',1,xcutc,ycutc,zcutc,rotxyc,rotyzc,rotzxc
*endif
!
*if,opt,eq,5,then
    create_cs,1,'circutcs',1,p1,p2,p3
*endif
!
*if,opt,eq,6,then
    csys,acs1
*endif
!
!
*do,ii,0,3*rtangle,rtangle
    k,,dia_cut/2,ii,0
*enddo
!
*if,dcut_,ne,0,then
    *if,(dia_cut/2-x),ge,0,then
        !
        *do,ii,0,3*rtangle,rtangle
            k,,(dia_cut/2-x),ii,-dcut_
        *enddo
        !
        init_entity_num
        !
        v,km-7,km-6,km-5,km-4,km-3,km-2,km-1,km
        !
        init_entity_num
        !
        vsbv,v2bcut,vm,,delete,delete
        !
        init_entity_num
        !
    *else
        init_entity_num
        !
        kdele,km-3,km,1
        !
        init_entity_num
    *endif
*else
    create_area,1
*endif
!
lplot
!
csys,_acs_
!
*set,xcutc, ! undefine parameters
*set,ycutc,
*set,zcutc,
*set,opt,
*set,acs1,
*set,rotxyc,
*set,rotyzc,
*set,rotzxc,
*set,phibev,
*set,dcut_,
*set,dia_cut,
*set,x,
*set,ii,
*set,_acs_,
!
abbres,new,tools,mac

*if,prkey_,eq,1,then
    /go
*endif