+
+class Variables:
+ # Container for variables
+ # Stores three sets of variables, the overall combined set, per layer, and per file
+ def __init__( self ):
+ # Dictionaries of variables
+ self.baseLayout = dict()
+ self.fileVariables = dict()
+ self.layerVariables = [ dict() ]
+ self.overallVariables = dict()
+ self.defines = dict()
+
+ self.currentFile = ""
+ self.currentLayer = 0
+ self.baseLayoutEnabled = True
+
+ def baseLayoutFinished( self ):
+ self.baseLayoutEnabled = False
+
+ def setCurrentFile( self, name ):
+ # Store using filename and current layer
+ self.currentFile = name
+ self.fileVariables[ name ] = dict()
+
+ # If still processing BaseLayout
+ if self.baseLayoutEnabled:
+ if '*LayerFiles' in self.baseLayout.keys():
+ self.baseLayout['*LayerFiles'] += [ name ]
+ else:
+ self.baseLayout['*LayerFiles'] = [ name ]
+ # Set for the current layer
+ else:
+ if '*LayerFiles' in self.layerVariables[ self.currentLayer ].keys():
+ self.layerVariables[ self.currentLayer ]['*LayerFiles'] += [ name ]
+ else:
+ self.layerVariables[ self.currentLayer ]['*LayerFiles'] = [ name ]
+
+ def incrementLayer( self ):
+ # Store using layer index
+ self.currentLayer += 1
+ self.layerVariables.append( dict() )
+
+ def assignVariable( self, key, value ):
+ # Overall set of variables
+ self.overallVariables[ key ] = value
+
+ # The Name variable is a special accumulation case
+ if key == 'Name':
+ # BaseLayout still being processed
+ if self.baseLayoutEnabled:
+ if '*NameStack' in self.baseLayout.keys():
+ self.baseLayout['*NameStack'] += [ value ]
+ else:
+ self.baseLayout['*NameStack'] = [ value ]
+ # Layers
+ else:
+ if '*NameStack' in self.layerVariables[ self.currentLayer ].keys():
+ self.layerVariables[ self.currentLayer ]['*NameStack'] += [ value ]
+ else:
+ self.layerVariables[ self.currentLayer ]['*NameStack'] = [ value ]
+
+ # If still processing BaseLayout
+ if self.baseLayoutEnabled:
+ self.baseLayout[ key ] = value
+ # Set for the current layer
+ else:
+ self.layerVariables[ self.currentLayer ][ key ] = value
+
+ # File context variables
+ self.fileVariables[ self.currentFile ][ key ] = value
+