!   TITLE:  ln_fillet.mac (SM_TOOL)
!
!
!       Made provision for filleting all newly created and/or unattached
!       lines that may be selected by the 'isolate_lines' command.
!
!       Made provision for creating a KP at the fillet arc center.
!
!       Made provision for non-standard fillets where lines are shorter
!       than the fillet radius.
!
!   OBJECTIVE:
!
!   This sub-macro creates a line fillet(s) at the specified junction key-
!   point(s).
!
!
!   COMMAND SYNTAX:
!
!                   (1)   (2)      (3)
!        LN_FILLET, jkp, radius, kp@cntr
!
!
!   ARGUMENTS:
!
!       (1) jkp = the keypoint number adjoining 2 lines to be filleted. This
!                 is a specific keypoint number (an integer value > or = to 0).
!
!               Otherwise:
!
!                   0 (or blank) = all selected keypoints adjoining two
!                                  lines will be filleted
!
!                   -1 = all unattached lines will be isolated ('isolate_lines'
!                        is automatically executed), and all keypoints adjoining
!                        two lines from this isolated line set will be filleted.
!
!
!       (2) radius = the radius of the fillet.
!
!       (3) kp@cntr = generates KP at the center point of the fillet radii:
!
!                   0 (or blank) = no center keypoint is generated.
!
!                   N = an arbitrarily chosen integer value greater than 0
!                       (N=1,2,3,.....). This argument enables the generation of
!                       a KP at the fillet arc center, assigning this KP a number
!                       equal to the numerical value of this argument plus the
!                       maximum keypoint number that is one of the end KP's of
!                       the fillet arc created (km+N).
!
!
!   DESCRIPTION:
!
!   This macro creates a fillet between 2 lines sharing the keypoint specified
!   in argument 1, 'jkp', with the fillet radius specified in argument 2.
!
!   If it is desired to create more than 1 fillet with the same radii, then
!   select all keypoints at the junction of the lines that are desired to be
!   filleted, and leave argument 1 blank. Fillets will be created at these
!   selected keypoints.
!
!   If any of the selected keypoints, or the specified keypoint 'jkp', are
!   not attached to only 2 lines, the algorithm will abort the fillet creation
!   at that keypoint, and proceed to the next junction keypoint in the selected
!   set, if more than 1 keypoint is selected.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
*get,actvcs_,active,,csys
!
jkp_=arg1
rad_=arg2
!
*if,arg3,ge,1,then
    cntrkp_=km+(arg3+2)
*else
    cntrkp_=0
*endif
!
*if,jkp_,le,0,then
    *if,jkp_,eq,-1,then
        isolate_lines
        ksll,s
    *endif
    !
    entity_array,'k','filkp_','array'
    numkps_=ecount
    !
    *do,abc_,1,numkps_,1
        ksel,s,kp,,filkp_(abc_,1)
        lslk,s,0
        jkp_=filkp_(abc_,1)
        !
        *get,lcnt_,line,,count
        get_max_entity
        get_min_entity
        ln_1st=l_min
        ln_2nd=lm
        !
        *if,lcnt_,eq,2,then
            *if,cntrkp_,gt,0,then
                *if,abc_,eq,1,then
                    kpoffst_=cntrkp_-km
                *else
                    cntrkp_=cntrkp_+kpoffst_
                *endif
            *endif
            !
            ns_fillet_test,rad_,ln_1st,ln_2nd
            !
            *if,non_stnd,eq,0,then
                lfillt,ln_1st,ln_2nd,rad_,cntrkp_
                kdele,jkp_
            *elseif,non_stnd,eq,1,then
                ns_ln_fillet,rad_,ln_1st,ln_2nd
            *endif
        *endif
    *enddo
    !
    *set,filkp_(1),
    *set,abc_,
    *set,numkps_,
    *set,ecount,
*elseif,jkp_,gt,0,then
    ksel,s,kp,,jkp_
    lslk,s,0
    !
    *get,lcnt_,line,,count
    get_max_entity
    get_min_entity
    ln_1st=l_min
    ln_2nd=lm
    !
    *if,lcnt_,eq,2,then
        ns_fillet_test,rad_,ln_1st,ln_2nd
        !
        *if,non_stnd,eq,0,then
            lfillt,ln_1st,ln_2nd,rad_,cntrkp_
            kdele,jkp_
        *elseif,non_stnd,eq,1,then
            ns_ln_fillet,rad_,ln_1st,ln_2nd
        *endif
    *endif
*endif
!
init_entity_num
!
csys,actvcs_
!
lplot
!
*set,jkp_,
*set,rad_,
*set,lcnt_,
*set,cntrkp_,
*set,ln_1st,
*set,ln_2nd,
*set,l_min,
*set,non_stnd,
*set,actvcs_,
*set,ln_1st,
*set,ln_2nd,
!
*if,prkey_,eq,1,then
    /go
*endif