##  Mem_Mtrl_Compare.py Version 1.00

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

##  All rights reserved.

##  NOT FOR SALE. The software is provided "as is" without any warranty.

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

"""

Select a member and recap the material in a dictionary.

"""

from param import ClearSelection

from mtrl_list import MtrlLocate

from member import Member, MemberLocate, MemberAllocated

from macrolib.columnize import columnize

from macrolib.material_list import mem_mtrl_list

 

cw = 8

 

def memMtrlDict(mem_list):

    if None in mem_list:

        return None, 0.0, None

    mtrlDict = {}

    tot_weight = 0.0

    for mem in mem_list:

        mList = mem_mtrl_list(mem)

        for m in mList:

            if mtrlDict.has_key(m.piecemark):

                mtrlDict[m.piecemark][0] += 1

            else:

                mtrlDict[m.piecemark] = [1, m.weight]

            tot_weight += m.weight

    return mtrlDict, tot_weight, mem_list

 

ClearSelection()

 

mtrlDict, total_weight, mem_list = memMtrlDict([MemberLocate('Select member'),])

mtrlDict1, total_weight1, mem_list1 = memMtrlDict([MemberLocate('Select member to compare'),])

 

keyList = mtrlDict.keys()

keyList.sort()

keyList1 = mtrlDict1.keys()

keyList1.sort()

 

try:   

    for i, key in enumerate(keyList):

        print '%s%s%s%s' % (columnize(key, cw, 'Center'), \

                            columnize(str(mtrlDict[key][0]), 4, 'Center'), \

                            columnize(keyList1[i], cw, 'Center'), \

                            columnize(str(mtrlDict1[keyList1[i]][0]), 4, 'Center')

                          )

except IndexError, e:

    'An IndexError occurred. The member to compare has fewer submaterials.'

except:

    'An unknown error occurred.'

 

print

 

ClearSelection()