ikeough/Dynamo — pull request #921 by ambarish-prakash (2013-12-11 10:15:31+00:00)
Title: Variable Redefinition

Variable Redefinition:
===

When variables are redefined in a new code block node, the node should go into an error state. To facilitate this, along with other conditions that derive from the same issue, the following commit is proposed.

Variable Definition Map:
---
To store the data with respect to the different defined variables and the nodes they have been defined in, a variable map was created that is stored in the Workspace. This map stores the defined variables along with the list of Guids of the Code Block Nodes that define that particular variable.

VariableDefinition Class:
---
This is a class that is used to store the variable definition map. It inherits from model base so that it may be recorded for undo/redo. It also has methods for saving and loading.

How It Works:
---
Whenever a code block nodes code (and hence variables it defines) changes, the table in the workspace is updated. If the variable was not yet defined, a new field is added to the map. Otherwise the GUID of the node is added to the end of the list related to that variable.

On re-validation, each required Code Block Node makes sure that the for each of its defined variables, the first GUID in the list of GUIDs mapped to the defined variable by the Map is the same as its own. If not, it is not the CBN that defined it and it is set to an erroneous state.

During Undo/Redo or Load/Save, the map is serialized as well and when all the nodes and map have been de-serialized, the nodes are re-validated.