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