!   TITLE:  ar_dist_pt_calc.mac (CALCULATION)
!
!
!           Implemented graphical picking option.
!
!   TOOLBAR MACRO
!
!   OBJECTIVE:
!
!   This GUI command macro calculates the linear distance between a planar
!   area and a keypoint.
!
!
!   ARGUMENTS:
!
!           1 prompt:   Area & Keypoint numbers to measure distance
!                       between:
!
!                                   AR# and KP#
!
!                       Decimal precision of output
!
!                                   PREC
!
!           NOTE: If the input boxes for the area & keypoint numbers are left
!                 to their default values of 0, then graphical picking is enabled.
!                 In this case, the user must select exactly 1 area and 1 keypoint
!                 only.
!
!
!   DESCRIPTION:
!
!   This macro calculates the perpendicular (minimum) distance between an area
!   and a keypoint. This distance is only valid if the input area is cartesian
!   planar.
!
!   The output is to a screen dialog box.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
entity_group
!
*get,acs1_,active,,csys
!
grphpic_=0
!
multipro,'start',3
    *cset,1,3,ar_,'Enter Area #',0
    *cset,4,6,kpt_,'Enter KP #',0
    *cset,7,9,prec_,'Enter Decimal Precision',4
    *cset,61,62,'Calculates the normal dist','ance between an area and'
    *cset,63,64,'a keypoint. Enter the area',' and KP numbers.'
multipro,'end'
!
*if,ar_,eq,0,then
    *if,kpt_,eq,0,then
        /ui,asel
        /ui,ksel
        get_max_entity
        !
        *get,acount_,area,,count
        *get,kcount_,kp,,count
        !
        ar_=am
        kpt_=km
        !
        grphpic_=1
    *endif
*endif
!
*if,grphpic_,eq,0,then
    ar1_=asel(ar_)
    kp1_=ksel(kpt_)
    !
    *if,ar1_,eq,1,then
        *if,kp1_,eq,1,then
            acount_=1
            kcount_=1
        *else
            acount_=1
            kcount_=0
        *endif
    *else
        *if,kp1_,eq,1,then
            acount_=0
            kcount_=1
        *else
            acount_=0
            kcount_=0
        *endif
    *endif
*endif
!
*if,acount_,eq,1,then
    *if,kcount_,eq,1,then
        *if,prec_,le,0,then
            prec_=4
        *endif
        !
        tol_=10**(-prec_-1)
        !
        asel,s,area,,ar_
        asum
        lsla,s
        ksll,s
        get_min_entity
        *get,kcnt_,kp,k_min,nxth
        !
        *get,acx_,area,,cent,x
        *get,acy_,area,,cent,y
        *get,acz_,area,,cent,z
        !
        csys,0
        k,,acx_,acy_,acz_
        get_max_entity
        xypt_=km
        !
        cskp,csn+5,0,kcnt_,k_min,xypt_
        kdele,xypt_
        get_max_entity
        !
        ksel,a,kp,,kpt_
        dist__=abs(kz(kpt_))
        !
        *if,abs(dist__),lt,tol_,then
            dist__=0
        *else
            *if,abs(dist__),ge,(10*tol_),then
                round_num,dist__,prec_
            *else
                round_num,dist__,prec_+1
            *endif
            !
            dist__=num_
        *endif
        !
*msg,ui,%ar_%,%kpt_%,%dist__%
Distance Between ( A %i , KP %i ) = %g
        !
        csdele,csn+5
        csys,acs1_
        !
        *set,dist__,
        *set,k_min,
        *set,kcnt_,
        *set,acs1_,
        *set,tol_,
        *set,xypt_,
    *endif
*endif
!
*if,acount_,gt,1,then
    *if,kcount_,gt,1,then
*msg,warn
Too Many Areas and KP's Picked. Must Select 1 each.
    *elseif,kcount_,lt,1,then
*msg,warn
Too Many Areas, Insufficient KP's Picked. Must Select 1 each.
    *elseif,kcount_,eq,1,then
*msg,warn
Too Many Areas Picked. Must Select 1 Only.
    *endif
*elseif,acount_,lt,1,then
    *if,kcount_,gt,1,then
*msg,warn
Insufficient Areas and Too Many KP's Picked. Must Select 1 each.
    *elseif,kcount_,lt,1,then
*msg,warn
Insufficient Areas and KP's Picked. Must Select 1 each.
    *elseif,kcount_,eq,1,then
*msg,warn
Insufficient Areas Picked. Must Select 1 Only.
    *endif
*elseif,acount_,eq,1,then
    *if,kcount_,gt,1,then
*msg,warn
Too Many KP's Picked. Must Select 1 each.
    *elseif,kcount_,lt,1,then
*msg,warn
Insufficient KP's Picked. Must Select 1 each.
    *endif
*endif
!
entity_group,1
!
*set,ar_,
*set,kpt_,
*set,prec_,
*set,ar1_,
*set,kp1_,
*set,acount_,
*set,kcount_,
*set,grphpic_,
!
*if,prkey_,eq,1,then
    /go
*endif