Allow for nested groups in gen_sct
This commit is contained in:
@ -301,6 +301,7 @@ def p_group_statement_list(p):
|
||||
def p_group_statement(p):
|
||||
'''group_statement : group_assignment
|
||||
| variable
|
||||
| group
|
||||
'''
|
||||
p[0] = p[1]
|
||||
|
||||
@ -626,10 +627,14 @@ def build_group(MyDriver, p):
|
||||
if len(ContextStack[ContextIndex]['path']) > 0:
|
||||
ContextStack[ContextIndex]['path'] += '/'
|
||||
ContextStack[ContextIndex]['path'] += p[0]['name']
|
||||
MyGroup['path'] = ContextStack[ContextIndex]['path']
|
||||
for item in p:
|
||||
if 'Variable' in item:
|
||||
MyVar = build_variable(MyDriver, item['Variable'])
|
||||
MyGroup['Vars'][MyVar['name']] = MyVar
|
||||
elif 'Group' in item:
|
||||
MySubGroup = build_group(MyDriver, item['Group'])
|
||||
MyGroup['Groups'][MySubGroup['name']] = MySubGroup
|
||||
else:
|
||||
if Verbose:
|
||||
print "Group Item:", item
|
||||
@ -682,28 +687,30 @@ def build_driver(MyDriver, TheTree):
|
||||
#
|
||||
# Driver Dump Functions
|
||||
#
|
||||
def dump_driver_vars(vars):
|
||||
def dump_driver_vars(vars, indent):
|
||||
global FunctionTypes
|
||||
global DriveableFunctionTypes
|
||||
for item in sorted(vars):
|
||||
print ' VAR %s = {' % item
|
||||
print indent + ' VAR %s = {' % item
|
||||
for subitem in sorted([i for i in vars[item] if i not in FunctionTypes + DriveableFunctionTypes]):
|
||||
print ' %s =' % subitem, vars[item][subitem]
|
||||
print indent + ' %s =' % subitem, vars[item][subitem]
|
||||
for subitem in sorted([i for i in vars[item] if i in FunctionTypes]):
|
||||
print ' %s =' % subitem, vars[item][subitem]
|
||||
print indent + ' %s =' % subitem, vars[item][subitem]
|
||||
for subitem in sorted([i for i in vars[item] if i in DriveableFunctionTypes]):
|
||||
print ' %s =' % subitem, vars[item][subitem]
|
||||
print ' }'
|
||||
def dump_driver_groups(groups):
|
||||
print indent + ' %s =' % subitem, vars[item][subitem]
|
||||
print indent + ' }'
|
||||
|
||||
def dump_driver_groups(groups, indent):
|
||||
for item in sorted(groups):
|
||||
if item:
|
||||
print ' GROUP ' + item + ' = {'
|
||||
print indent + 'GROUP ' + item + ' = {'
|
||||
else:
|
||||
print ' GROUP = {'
|
||||
print indent + 'GROUP = {'
|
||||
for subitem in sorted([x for x in groups[item] if not x in ['Groups', 'Vars']]):
|
||||
print ' ', subitem, '=', groups[item][subitem]
|
||||
dump_driver_vars(groups[item]['Vars'])
|
||||
print ' }'
|
||||
print indent + ' ', subitem, '=', groups[item][subitem]
|
||||
dump_driver_vars(groups[item]['Vars'], indent)
|
||||
dump_driver_groups(groups[item]['Groups'], indent + ' ')
|
||||
print indent + '}'
|
||||
|
||||
def dump_driver_funcs(funcs):
|
||||
for item in sorted(funcs):
|
||||
@ -720,7 +727,7 @@ def dump_driver(MyDriver):
|
||||
for item in sorted([x for x in MyDriver if x not in ['Groups', 'Funcs']]):
|
||||
print ' ' + item + ' =', MyDriver[item]
|
||||
#print 'Groups:', MyDriver['Groups']
|
||||
dump_driver_groups(MyDriver['Groups'])
|
||||
dump_driver_groups(MyDriver['Groups'], ' ')
|
||||
#print 'Funcs:', MyDriver['Funcs']
|
||||
dump_driver_funcs(MyDriver['Funcs'])
|
||||
print '}'
|
||||
@ -1030,11 +1037,11 @@ def put_group(MyDriver, MyGroup):
|
||||
txt = []
|
||||
if MyGroup['name']:
|
||||
txt += ['']
|
||||
txt += [' hfactory ${scobj_hpath}/%s plain spy none' % MyGroup['name']]
|
||||
txt += [' hfactory ${scobj_hpath}/%s plain spy none' % MyGroup['path']]
|
||||
if 'GroupProperty' in MyGroup:
|
||||
for key in sorted(MyGroup['GroupProperty']):
|
||||
txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (MyGroup['name'], key, MyGroup['GroupProperty'][key])]
|
||||
groupname = MyGroup['name'] + '/'
|
||||
txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (MyGroup['path'], key, MyGroup['GroupProperty'][key])]
|
||||
groupname = MyGroup['path'] + '/'
|
||||
else:
|
||||
groupname = ''
|
||||
for var in sorted(MyGroup['Vars']):
|
||||
@ -1042,7 +1049,7 @@ def put_group(MyDriver, MyGroup):
|
||||
MyVar = MyGroup['Vars'][var]
|
||||
nodename = groupname + MyVar['name']
|
||||
# Check driveable attributes are present if required
|
||||
if MyVar['driveable']:
|
||||
if 'driveable' in MyVar and MyVar['driveable']:
|
||||
for attr in ('lowerlimit', 'upperlimit', 'tolerance'):
|
||||
if attr not in MyVar:
|
||||
msg = 'Driveable: %s does not have required attribute: %s' % (nodename, attr)
|
||||
@ -1158,6 +1165,8 @@ def put_group(MyDriver, MyGroup):
|
||||
if MyVar['driveable']:
|
||||
txt += [' ansto_makesctdrive ${name}_%s ${scobj_hpath}/%s ${scobj_hpath}/%s ${sct_controller}' % (MyVar['name'], nodename, MyVar['driveable'])]
|
||||
txt += [' }']
|
||||
for grp in sorted(MyGroup['Groups']):
|
||||
txt += put_group(MyDriver, MyGroup['Groups'][grp])
|
||||
return txt
|
||||
|
||||
def put_mk_sct_driver(MyDriver):
|
||||
@ -1305,9 +1314,9 @@ def process_drivers(TheDrivers):
|
||||
build_driver(MyDriver, TheDrivers[driver])
|
||||
if Verbose:
|
||||
print "MyDriver:", MyDriver['name'], '=', MyDriver
|
||||
generate_driver(MyDriver)
|
||||
if DriverDump or Verbose:
|
||||
dump_driver(MyDriver)
|
||||
generate_driver(MyDriver)
|
||||
|
||||
def process_source(source_files):
|
||||
global PathName
|
||||
|
Reference in New Issue
Block a user