DynamoDS/Dynamo — pull request #3214 by Randy-Ma (2014-11-21 09:55:17+00:00)
Title: Fix MAGN-3960 and MAGN-4593

Summary

This submission is trying to fix two defects: MAGN-3960 and MAGN-4593. For the two functions: SetParameterByName and GetParameterValueByName, GetParameterValueByName returns length, area and volume with a symbolic unit, this is not convenient for users to do downstream calculations, while for SetParameterByName, the int/double value for length, area and volume will be always considered in meters, square meters or cubic meters no matter what is the current settings in the Dynamo settings. But actually the settings can be different.
![image](https://cloud.githubusercontent.com/assets/5584246/5140287/1651a920-71a4-11e4-971d-a34c86a34ce0.png)

@kronz
I think it is more reasonable to take the int/double values in the unit of the Dynamo settings other than the project unit set in Revit. In this submission, I am following the Dynamo settings. If we want to follow the Revit project unit, I will make corresponding changes. But currently I have not figured out a way to know when the project unit changes in Revit and act correspondingly.

@pboyer
In this submission, I am keeping the internal value of SIUnit in meter. I added a new derived class UIUnit which will return value according to the current Dynamo unit settings. The method ValueInDynamoUIUnits is for this purpose.

Then for Length, Area and Volume classes, I am deriving from UIUnit so that ValueInDynamoUIUnits can be implemented. This method is then used in the places where it relates to the Dynamo UI settings. Then FromDoubleInUIUnit is implemented to be used in the proper places.

When the unit settings is changed, all nodes will be marked dirty and the graph can be run again. I have added a new event handler in NodeModel.

New Behaviors

1. The int/double value to be set or returned from SetParameterByName and GetParameterValueByName is considered to be in the current unit settings in Dynamo for Length, Area and Volume.
2. The int/double value to be set or returned for other nodes will be considered to be in the current unit settings in Dynamo for Length, Area and Volume.
3. When the Length, Area or Volume unit is changed in Dynamo, the graph will run again if "Run Automatically" is on. The output int/double value will change. But the input int/double value will not change.

Test

I have run the related test cases under UnitsOfMeasureTests. They are passing.

The following is a series of picture for a graph when I am changing the Dynamo length unit:
1. The length unit is meter:
![image](https://cloud.githubusercontent.com/assets/5584246/5140570/21757a4a-71a7-11e4-97f7-ac8e5c2304c2.png)

2. The length unit is changed to centimeter:
![image](https://cloud.githubusercontent.com/assets/5584246/5140596/40c4fe02-71a7-11e4-8e37-0d90c9a7ba10.png)

3. The length unit is changed to decimal foot:
![image](https://cloud.githubusercontent.com/assets/5584246/5140612/594acf9c-71a7-11e4-9fee-f098ed47a9b9.png)

Reviewers

- [ ] @pboyer
- [ ] @kronz