!   TITLE:  parl_lines.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This macro creates a series of lines parallel to a set of selected lines.
!
!
!   COMMAND SYNTAX:
!
!                     (1)   (2)   (3)    (4)    (5)    (6)     (7)   (8)
!        PARL_LINES, plncs, side, dist, line#, sfact, zposCS, zposL, npl
!
!
!   ARGUMENTS:
!
!       (1) plncs = the coordinate system whose XY plane is parallel to
!                   the plane which wiil contain the parrallel lines.
!
!       (2) side = the side to the selected line to create the parallel line.
!
!                       't' = top
!                       'b' = bottom
!                       'l' = left
!                       'r' = right
!
!               *** NOTE: For vertical and horizontal lines, it is safest to
!                         specify the sides as follows:
!
!                           vertical - left ('l') or right ('r')
!                           horizontal - top ('t') or bottom ('b')
!
!
!       (3) dist =  the distance between parallel lines
!
!       (4) line# =  number of the line to construct parrallel to. This
!                    argument is valid only when an individual line is to
!                    be selected. (If a multiple-line set (>1) is to be
!                    used, then this argument is left blank, and the lines
!                    to be operated on are selected)
!
!       (5) sfact = new line length scaling factor (default = 2)
!
!       (6) zposCS = new line Z position RELATIVE to the plane C.S., which is
!                    the plane normal to the Z axis of the plane C.S. specified
!                    in argument 1.
!
!       (7) zposL = new line Z position RELATIVE to plane of the original line,
!                   which is the plane normal to the Z axis of the plane C.S.
!                   specified in argument 1.
!
!       (8) npl = number of consecutive parallel lines being created. This para-
!                 meter is specified in the first call of PARL_LINES when a group
!                 of parallel lines is to be created one after the other.
!
!
!   DESCRIPTION:
!
!   The parrallel line(s) are created in the plane parallel to the XY plane
!   of the plane coordinate system specified in argument 1, 'plncs'.
!
!   This macro creates the parallel line(s) a normal distance 'dist' from
!   the selected lines.  The lines are created on the side specified by
!   argument 2.  TOP, BOTTOM, LEFT and RIGHT are relative positions, and
!   are based on the perspective of the user.  This 'perspective' is deter-
!   mined from the plane coordinate system specified in argument 1. From,
!   this coordinate system, TOP is the region in the +Y direction; BOTTOM is
!   the region in the -Y direction; LEFT is the region in the -X direction
!   and RIGHT is the region in the +X direction.  Therefore, the perspective
!   of the user is the XY plane with the +Z axis pointing out of the graphics
!   window.
!
!   The length of the new lines are determined by the scaling factor, 'sfact',
!   specified in argument 4.  If left blank, the default value is 2.
!
!   The length of the new line is determined by the following formula:
!
!                       L_new = L_orig + 2*(sfact * dist)
!
!   where  L_new = length of the new line
!          L_orig = length of the original (selected) line
!
!   This line is centered parallel with the original line, with each end
!   greater in length by the amount (sfact * dist). Argument 5 allows the
!   user to adjust the resulting lengths of the new lines if desired.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
plncs_=arg1
side_=arg2
dist_=arg3
origln_=arg4
sfact_=arg5
zposcs_=arg6
zposl_=arg7
npl_=arg8
!
*if,npl_,gt,0,then
    excnt_=0                ! initialize execution counter for PARL_LINES
    nplhold_=npl_
*endif
!
*if,nplhold_,gt,0,then
    *if,npl_,eq,0,then
        excnt_=excnt_+1
    *endif
*endif
!
*if,origln_,ne,0,then
    origln_=origln_-excnt_
*endif
!
*if,sfact_,le,0,then
    sfact_=2
*endif
!
*get,acs1__,active,,csys
!
*get,plncstyp,cdsy,plncs_,attr,kcs
!
*if,plncstyp,ne,0,then
    clocal,csn+5,0,0,0,0,0,0,0
*endif
!
*if,origln_,eq,0,then
    cm,origlns_,line
*else
    lsel,s,line,,origln_
*endif
!
entity_array,'l','parln_','array'
lnmax_=ecount
!
*do,aaa_,1,lnmax_,1
    csys,plncs_
    !
    *get,lnl_,line,parln_(aaa_,1),leng
    !
    *get,kp11_,line,parln_(aaa_,1),kp,1
    *get,kp12_,line,parln_(aaa_,1),kp,2
    !
    offset_=kz(kp11_)
    clocal,csn+6,1,kx(kp11_),ky(kp11_),offset_,0,0,0
    !
    kpang_=ky(kp12_)
    ang_convert,'kpang_',0
    !
    *if,kpang_,le,89,then
        k,,1,90,0
    *elseif,kpang_,le,179,then
        k,,1,180,0
    *elseif,kpang_,le,269,then
        k,,1,270,0
    *elseif,kpang_,le,359,then
        k,,1,0,0
    *elseif,kpang_,gt,359,then
        k,,1,90,0
    *endif
    !
    init_entity_num
    thrdkp_=km
    !
    cskp,csn+7,0,kp11_,kp12_,thrdkp_
    !
    *if,kpang_,le,90,then
        *if,side_,eq,'t',then
            sign_=1
        *elseif,side_,eq,'b',then
            sign_=-1
        *elseif,side_,eq,'l',then
            sign_=1
        *elseif,side_,eq,'r',then
            sign_=-1
        *endif
    *elseif,kpang_,le,180,then
        *if,side_,eq,'t',then
            sign_=-1
        *elseif,side_,eq,'b',then
            sign_=1
        *elseif,side_,eq,'l',then
            sign_=1
        *elseif,side_,eq,'r',then
            sign_=-1
        *endif
    *elseif,kpang_,le,270,then
        *if,side_,eq,'t',then
            sign_=-1
        *elseif,side_,eq,'b',then
            sign_=1
        *elseif,side_,eq,'l',then
            sign_=-1
        *elseif,side_,eq,'r',then
            sign_=1
        *endif
    *elseif,kpang_,le,360,then
        *if,side_,eq,'t',then
            sign_=1
        *elseif,side_,eq,'b',then
            sign_=-1
        *elseif,side_,eq,'l',then
            sign_=-1
        *elseif,side_,eq,'r',then
            sign_=1
        *endif
    *endif
    !
    *if,zposcs_,eq,0,then
        *if,zposl_,eq,0,then
            zpos_=0
        *else
            zpos_=zposl_
        *endif
    *else
        zpos_=zposcs_-offset_
    *endif
    !
    *if,dist_,ne,0,then
        k,,-sfact_*dist_,sign_*dist_,zpos_
        k,,lnl_+(sfact_*dist_),sign_*dist_,zpos_
    *else
        k,,-sfact_*(0.10*lnl_),0,zpos_
        k,,lnl_+(sfact_*(0.10*lnl_)),0,zpos_
    *endif
    !
    create_lines,,1
    !
    kdele,thrdkp_
    init_entity_num
    !
    lplot
*enddo
!
lsel,s,line,,lm-(aaa_-1),lm,1
cm,newlns,line
!
init_entity_num
!
*if,usangln_,ne,1,then
    csdele,csn+5,csn+7,1
*endif
!
lplot
!
csys,acs1__
!
*if,excnt_,eq,nplhold_-1,then
    *set,excnt_,
    *set,nplhold_,
*endif
!
*set,plncs_,
*set,acs1__,
*set,origln_,
*set,plncstyp,
*set,lnmax_,
*set,parln_(1),
*set,kpang_,
*set,sign_,
*set,sfact_,
*set,lnl_,
*set,thrdkp_,
*set,dist_,
*set,side_,
*set,aaa_,
*set,kp11_,
*set,kp12_,
*set,zpos_,
*set,zposl_,
*set,zposcs_,
*set,offset_,
*set,npl_,

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