## Copyright (c) 2006 Bruce Vaughan, BV Detailing & Design, Inc.

## All rights reserved.

## PrintPtList.py Version 1.01

###############################################################

""" Return a formatted string of a list of points

    Library module PrintPtList

    function 'formatPtList' and 'formatPtList_'

    Place in directory 'SDS/2 root data'/macro/macrolib.

    Create the directory if it does not exist.

    This file can be executed as a stand alone parametric.

   

    Example import:

    from macrolib.PrintPtList import formatPtList

   

    Example usage:

    str1 = formatPtList("Point List:", pt_list)

    print str1

 

    This function can be useful when debugging a parametric.

 

    Revision History:

    Version 1.00 (11/11/06) -  Initial version

    Version 1.01 (12/12/06) -  Add formatPtList_ (uses library function fifDim)

                               Format point attributes in columns

"""

 

# field width for point attributes

fw = 20

# pad field function

def pf(s, f):

    return s + (" " * (fw - len(s)))

 

# SEE EXAMPLE USAGE IN 'test_formatPtList()' BELOW

def formatPtList(hdr_str, lst):

    from param import dim_print

    ret_str = hdr_str + '\n' + "%s%s%s\n%s\n" % (pf('X attribute', fw), pf('Y attribute', fw), pf('Z attribute', fw), "=" * 3*fw)

    for i in lst:

        ret_str = ret_str + "%s%s%s\n" % (pf(dim_print(i.x), fw), pf(dim_print(i.y), fw), pf(dim_print(i.z), fw))

    return ret_str

 

def formatPtList_(hdr_str, lst):

    from macrolib.fifDim import fifDim

    ret_str = hdr_str + '\n' + "%s%s%s\n%s\n" % (pf('X attribute', fw), pf('Y attribute', fw), pf('Z attribute', fw), "=" * 3*fw)

    for i in lst:

        ret_str = ret_str + "%s%s%s\n" % (pf(fifDim(i.x), fw), pf(fifDim(i.y), fw), pf(fifDim(i.z), fw))

    return ret_str

 

def test_formatPtList():

    from point import Point, PointLocate

    pt_list = []

    while True:

        pt = PointLocate("Select Point")

        if pt:

            pt_list.append(pt)

        else:

            break

    # print formatted list of points

    print formatPtList("Points List:", pt_list)

    print formatPtList_("Points List:", pt_list)

 

## END test_formatPtList() ###############################

if __name__ == '__main__':

    try:

        test_formatPtList()

    finally:

        del test_formatPtList

        del formatPtList