•  

    kill !!KwiTubePos
    
    Setup Form !!KwiTubePos
        title 'Fec : Tube Level'
        init  '!this.initial()'
    
        button .CE at X0.5 Y 0.2  ' CE '   call |!this.Ce()|
        button .Pick at Xmax +3 Ymin  'Pick' call |!this.Pick()|
        button .Erase at Xmax+3 Ymin  'Erase Aids' call |!this.Clear()|
    
        halign right
        path down
        textpane .text at X0.5 Ymax+.2 'Tube Position' width 26 height 6
    
        button .Dismiss at Ymax-.5  'Dismiss' call |!this.clear()| Cancel
    
        member .bmem is string
        member .color is string
    exit
    
    
    -----------------------------------------------
    Define Method .initial()
      !Out[1] = ''
      !this.text.val = !Out
      var !AidCol colour aids
      !this.color = '$!AidCol'
    EndMethod
    
    -----------------------------------------------
    Define Method .CE()
        !ce = !!ce
        !this.GetPos()
        $!ce
    EndMethod
    
    -----------------------------------------------
    Define Method .Pick()
        !ce = !!ce
        prompt dismiss
        prompt off
        prompt load escape |Identify element to be cheched or -Escape-|
        var !pick PICK
          handle any
          endhandle
        prompt on
        if (!pick.set()) then
            !this.bmem = !pick[1]
            $!this.bmem
            !this.GetPos()
        endif
        $!CE
    EndMethod
    
    -----------------------------------------------
    Define Method .GetPos()
        !type = !!ce.type
        if (!!ce.type eq 'BRAN') then
           !this.GetPosB()
        elseif (!!ce.owne.type eq 'BRAN') then
           !this.GetPosM()
        elseif (!!ce.type eq 'NOZZ') then
           !this.GetNozPos()
        endif
    EndMethod
    
    
    -----------------------------------------------
    Define Method .GetPosM()
        -- Check Leave Direction
        !Out = object array()
        !Ldir = LDIR
        if ( abs(!Ldir.up) lt 1 ) then
              !tmp = LTOP
            !LTOP = !tmp.up.string('d2')
              !tmp = LPOS
            !LCOP = !tmp.UP.string('d2')
              !tmp = LBOP
            !LBOP = !tmp.up.string('d2')
    
            !Out.append(|Elevation |)
            !Out.append(|  TOP: $!LTOP|)
            !Out.append(|  COP: $!LCOP|)
            !Out.append(|  BOP: $!LBOP|)
    
    
            !this.ShowArrow(LBOP, '', LBOR)
    
            if ( abs(!Ldir.up) neq 0) then   $***********:
                !this.ShowArrow(LBOP, 'Start', LBOR)
                next
                handle (2,113)   $*  End
                      !tmp = PT TOP of Bran
                    !ATOP = !tmp.up.string('d1')
                      !tmp = PT POS of Bran
                    !ACOP = !tmp.UP.string('d1')
                      !tmp = PT BOP of Bran
                    !ABOP = !tmp.up.string('d1')
                    !BORE = PTBOR
                elsehandle NONE
                      !tmp = ATOP
                    !ATOP = !tmp.up.string('d1')
                      !tmp = APOS
                    !ACOP = !tmp.UP.string('d1')
                      !tmp = ABOP
                    !ABOP = !tmp.UP.string('d1')
                    !BORE = ABOR
                endhandle
                !Out[1] = |Elev. at Start Point|
                !Out.append(|Elev. at End Point|)
                !Out.append(|  TOP: $!ATOP|)
                !Out.append(|  COP: $!ACOP|)
                !Out.append(|  BOP: $!ABOP|)
                !this.ShowArrow(!tmp, 'End', !bore)
    
            endif
        else
              !posu = !!ce.pos.up.real()
            !Out.append(|   Pos = $!posu |)
    
            !Out.append(| Not Horizontal Line |)
            !Out.append(| Try Again|)
    
        endif
        !this.text.val = !Out
    EndMethod
    
    
    -----------------------------------------------
    Define Method .GetPosB()
        -- Check Leave Direction
        !Out = object array()
    
        !grad = PHGR
        if (abs(!grad) lt 0.1) then
              !tmp = PH TOP of Bran
            !LTOP = !tmp.up.string('d1')
              !tmp = PH POS of Bran
            !LCOP = !tmp.UP.string('d1')
              !tmp = PH BOP of Bran
            !LBOP = !tmp.up.string('d1')
    
            !Out.append(|Elevation |)
            !Out.append(|  TOP: $!LTOP|)
            !Out.append(|  COP: $!LCOP|)
            !Out.append(|  BOP: $!LBOP|)
    
            !this.ShowArrow(PHBP, '', PHBOR)
    
            if (!grad neq 0) then
                !this.ShowArrow(PHBP, 'Start', PHBOR)
    
                First member
                handle (2,113)   $*  No Member
                      !tmp = PT TOP of Bran
                    !ATOP = !tmp.up.string('d1')
                      !tmp = PT POS of Bran
                    !ACOP = !tmp.UP.string('d1')
                      !tmp = PT BOP of Bran
                    !ABOP = !tmp.up.string('d1')
                    !BORE = PTBOR
                elsehandle NONE
                      !tmp = ATOP
                    !ATOP = !tmp.up.string('d1')
                      !tmp = APOS
                    !ACOP = !tmp.UP.string('d1')
                      !tmp = ABOP
                    !ABOP = !tmp.up.string('d1')
                    !BORE = ABOR
                endhandle
                !Out[1] = |Elev. at Start Point|
                !Out.append(|Elev. at End Point|)
                !Out.append(|  TOP: $!ATOP|)
                !Out.append(|  COP: $!ACOP|)
                !Out.append(|  BOP: $!ABOP|)
    
                !this.ShowArrow(!tmp, 'End', !bore)
            endif
        else
    
            !Out.append(| Not Horizontal Line |)
            !Out.append(| Try Again|)
        endif
        !this.text.val = !Out
    EndMethod
    
    -----------------------------------------------
    Define Method .GetNozPos()
      !Out = object array()
    
      !pos1 = !!ce.pos.up.real()
      !pos2 = !!ce.pos.wrt(ZONE).up.real()
    
      !Out.append(|Nozzle |)
      !Out.append(|  Position: $!pos1 wrt Equip|)
      !Out.append(|  Position: $!pos2 wrt Zone |)
      !this.text.val = !Out
    
      !this.ShowArrow(POS, '', P1BORE)
    EndMethod
    
    
    -----------------------------------------------
    Define Method .ShowArrow(!cpos is position, !text is string, !diam is bore)
       color aids red
       aid clear all
       !hei =  200
       !dia = !diam.real() / 2
       !pos = !cpos
    
    --   !pos.up = ( !pos.up - !dia - !hei )
       !pos.up = ( !pos.up - !hei )
        aid arrow  at $!pos  dir u hei ( $!hei )
        if (!text neq '') then
            aid text num 1 '$!text' at $!pos
        endif
    EndMethod
    
    
    
    -----------------------------------------------
    Define Method .Clear()
       color aids $!this.color
       aid clear arrow all
       aid clear Text all
    EndMethod
    
    $.