Show
Ignore:
Timestamp:
03/27/12 10:15:44 (14 months ago)
Author:
Snyder.Jason
Message:

changes related to alternate component implementations

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ossiedev/branches/jsnyder/trunk/tools/WaveDev/wavedev/importNode.py

    r10753 r11083  
    152152        newComp.xmlName =  os.path.splitext(os.path.splitext(os.path.basename(pathSCD))[0])[0] 
    153153 
    154         newNode.Devices.append(newComp) 
     154         
    155155 
    156156        # 
     
    182182        #            continue 
    183183        #        newComp.properties.append(p) 
     184        # 
     185        # Import the properties from the PRF file 
     186        # 
     187         
     188        # If there are no properties, just return the component as is 
     189        tmp = doc_spd.getElementsByTagName("propertyfile") 
     190        if len(tmp) > 0: 
     191            propertyFileNode = tmp[0] 
     192            propertyFile = '/sdr/dev' + propertyFileNode.getElementsByTagName("localfile")[0].getAttribute("name") 
     193            propertyDoc = xml.dom.minidom.parse(propertyFile) 
     194            simplePropNodes = propertyDoc.getElementsByTagName("simple") 
     195            simpleProps = getSimpleProperties(simplePropNodes, propertyFile) 
     196             
     197            for prop in simpleProps: 
     198                newComp.properties.append(prop) 
     199             
     200            simpleSequencePropNodes = propertyDoc.getElementsByTagName("simplesequence") 
     201            simpleSequenceProps = getSimpleSequenceProperties(simpleSequencePropNodes, propertyFile) 
     202             
     203            for prop in simpleSequenceProps: 
     204                newComp.properties.append(prop) 
     205        else: 
     206            propertyFile = None 
     207     
     208        
     209         
     210        newNode.Devices.append(newComp) 
    184211 
    185212    return newNode 
     
    233260    return xml 
    234261 
     262def getSimpleProperties(simplePropertyNodeList, propertyFile): 
     263    props = [] 
     264    for node in simplePropertyNodeList: 
     265        p = getSimpleProperty(node) 
     266        if p == None: 
     267            print "There was an error parsing simple properties in the PRF file " + propertyFile 
     268            continue 
     269        props.append(p) 
     270         
     271    return props 
     272 
     273def getSimpleSequenceProperties(simpleSequencePropertyNodeList, propertyFile): 
     274    props = [] 
     275    for node in simpleSequencePropertyNodeList: 
     276        p = getSimpleSequenceProperty(node, propertyFile) 
     277        if p == None: 
     278            print "There was an error parsing simple sequence properties in the PRF file " + propertyFile 
     279            continue 
     280        props.append(p) 
     281         
     282    return props 
     283 
     284def getSimpleProperty(n): 
     285    tmpName = n.getAttribute("name") 
     286    tmpID   = n.getAttribute("id") 
     287    tmpType = n.getAttribute("type") 
     288    tmpMode = n.getAttribute("mode") 
     289    tmpDes = n.getAttribute("description") 
     290 
     291    if tmpName == "" or tmpID == "" or tmpType == "" or tmpMode == "": 
     292        return None 
     293    if tmpMode not in availableModes: 
     294        return None 
     295    if tmpType not in availableTypes: 
     296        return None 
     297     
     298    newProp = CC.SimpleProperty(tmpName,tmpMode,tmpType,description=tmpDes) 
     299    
     300    # Set ID 
     301    #UUID in the sad file will need to match the UUID in the prf (tmpID is from prf) 
     302    newProp.id = tmpID 
     303 
     304    # Get/set property value 
     305    valueNodeList = n.getElementsByTagName("value") 
     306    value = valueNodeList[0].childNodes[0].data 
     307    newProp.value = newProp.defaultValue = str(value) 
     308    del valueNodeList, value 
     309     
     310    # Get/set property units 
     311    unitsNodeList = n.getElementsByTagName("units") 
     312    if len(unitsNodeList) > 0: 
     313        units = unitsNodeList[0].childNodes[0].data 
     314        newProp.units = str(s.units) 
     315    #del unitsNodeList, units 
     316     
     317    # TODO: Get/set min/max values 
     318    # TODO: Get/set enum 
     319     
     320    # Get/set kind 
     321    kindNodeList = n.getElementsByTagName("kind") 
     322    kindtype = kindNodeList[0].getAttribute("kindtype") 
     323    if kindtype == "": 
     324        return None 
     325    newProp.kind = str(kindtype) 
     326    del kindNodeList, kindtype 
     327     
     328    # Get/set action 
     329    actionNodeList = n.getElementsByTagName("action") 
     330    if len(actionNodeList) > 0: 
     331        actiontype = actionNodeList[0].getAttribute("type") 
     332        newProp.action = str(actiontype) 
     333    #del actionNodeList, actiontype 
     334         
     335    return newProp 
     336     
     337def getSimpleSequenceProperty(n, prfPath): 
     338    tmpName = n.getAttribute("name") 
     339    tmpID   = n.getAttribute("id") 
     340    tmpType = n.getAttribute("type") 
     341    tmpMode = n.getAttribute("mode") 
     342    tmpDes = n.getAttribute("description") 
     343 
     344    if tmpName == "" or tmpID == "" or tmpType == "" or tmpMode == "": 
     345        return None 
     346    if tmpMode not in availableModes: 
     347        return None 
     348    if tmpType not in availableTypes: 
     349        return None 
     350     
     351    newProp = CC.SimpleSequenceProperty(tmpName,tmpMode,tmpType,description=tmpDes) 
     352    
     353    # Set ID 
     354    #UUID in the sad file will need to match the UUID in the prf (tmpID is from prf) 
     355    newProp.id = tmpID 
     356 
     357 
     358    # Get/set property values 
     359    newProp.values = [] 
     360    newProp.defaultValues = [] 
     361    valuesNodeList = n.getElementsByTagName("values") 
     362     
     363    try: 
     364        valueNodeList = valuesNodeList[0].getElementsByTagName("value") 
     365    except: 
     366        valueNodeList = n.getElementsByTagName("value") #cbd 
     367        #print "\nERROR in " + prfPath 
     368        #print "ERROR parsing prf file.  You may be missing a values tag in a simple sequence property.\n" 
     369        #sys.exit() 
     370        print "\nWarning in " + prfPath 
     371        print "Warning parsing prf file.  You may be missing a values tag in a simple sequence property.\n" 
     372 
     373    for valueNode in valueNodeList: 
     374        tmpVal = valueNode.childNodes[0].data 
     375        newProp.values.append(str(tmpVal)) 
     376        newProp.defaultValues.append(str(tmpVal)) 
     377    del valueNodeList 
     378 
     379    # Get/set property units 
     380    unitsNodeList = n.getElementsByTagName("units") 
     381    if len(unitsNodeList) > 0: 
     382        units = unitsNodeList[0].childNodes[0].data 
     383        newProp.units = str(s.units) 
     384    #del unitsNodeList, units 
     385     
     386    # TODO: Get/set min/max values 
     387    # TODO: Get/set enum 
     388     
     389    # Get/set kind 
     390    kindNodeList = n.getElementsByTagName("kind") 
     391    kindtype = kindNodeList[0].getAttribute("kindtype") 
     392    if kindtype == "": 
     393        return None 
     394    newProp.kind = str(kindtype) 
     395    del kindNodeList, kindtype 
     396 
     397    # Get/set action 
     398    actionNodeList = n.getElementsByTagName("action") 
     399    if len(actionNodeList) > 0: 
     400        actiontype = actionNodeList[0].getAttribute("type") 
     401        newProp.action = str(actiontype) 
     402    #del actionNodeList, actiontype 
     403 
     404    return newProp 
     405 
     406