Skip to content

Commit 2574b5d

Browse files
author
Jeremy Tammik
committed
implemented MapDutToUt dictionary mapping each DisplayUnitType to a list of UnitType values that it may be used for by inverting the result of the UnitUtils.GetValidDisplayUnits method
1 parent 825014f commit 2574b5d

File tree

2 files changed

+74
-6
lines changed

2 files changed

+74
-6
lines changed

BuildingCoder/BuildingCoder/CmdDutAbbreviation.cs

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#region Namespaces
1010
using System;
11+
using System.Collections.Generic;
1112
using System.Linq;
1213
using Autodesk.Revit.ApplicationServices;
1314
using Autodesk.Revit.Attributes;
@@ -18,6 +19,58 @@
1819

1920
namespace BuildingCoder
2021
{
22+
/// <summary>
23+
/// Map each DisplayUnitType to a list of all the
24+
/// UnitType values that it might be used for, e.g.
25+
/// Meters is mapped to the following 21 values:
26+
/// Length, SheetLength, HVAC_DuctSize, HVAC_Roughness,
27+
/// PipeSize, Piping_Roughness, WireSize, DecSheetLength,
28+
/// Electrical_CableTraySize, Electrical_ConduitSize,
29+
/// Reinforcement_Length, HVAC_DuctInsulationThickness,
30+
/// HVAC_DuctLiningThickness, PipeInsulationThickness,
31+
/// Bar_Diameter, Crack_Width, Displacement_Deflection,
32+
/// Reinforcement_Cover, Reinforcement_Spacing,
33+
/// Section_Dimension, Section_Property.
34+
/// </summary>
35+
class MapDutToUt : Dictionary<DisplayUnitType, List<UnitType>>
36+
{
37+
public MapDutToUt()
38+
{
39+
IList<DisplayUnitType> duts;
40+
41+
Array a = Enum.GetValues( typeof( UnitType ) );
42+
43+
foreach( UnitType ut in a )
44+
{
45+
// Skip the UT_Undefined and UT_Custom entries;
46+
// GetValidDisplayUnits throws ArgumentException
47+
// on them, saying "unitType is an invalid unit
48+
// type. See UnitUtils.IsValidUnitType() and
49+
// UnitUtils.GetValidUnitTypes()."
50+
51+
if( UnitType.UT_Undefined == ut
52+
|| UnitType.UT_Custom == ut )
53+
{
54+
continue;
55+
}
56+
57+
duts = UnitUtils.GetValidDisplayUnits( ut );
58+
59+
foreach( DisplayUnitType dut in duts )
60+
{
61+
//Debug.Assert( !ContainsKey( dut ),
62+
// "unexpected duplicate DisplayUnitType key" );
63+
64+
if( !ContainsKey( dut ) )
65+
{
66+
Add( dut, new List<UnitType>( 1 ) );
67+
}
68+
this[dut].Add( ut );
69+
}
70+
}
71+
}
72+
}
73+
2174
[Transaction( TransactionMode.ReadOnly )]
2275
class CmdDutAbbreviation : IExternalCommand
2376
{
@@ -59,6 +112,8 @@ public Result Execute(
59112
Debug.Assert( 26 == (int) DisplayUnitType.DUT_LITERS, _s );
60113
#endregion // Assertions
61114

115+
MapDutToUt map_dut_to_ut = new MapDutToUt();
116+
62117
DisplayUnitType n
63118
= DisplayUnitType.DUT_GALLONS_US;
64119

@@ -67,23 +122,36 @@ DisplayUnitType n
67122
+ "abbreviation and the valid unit symbols:\n",
68123
(int) n - 1 );
69124

70-
string valid_unit_symbols;
125+
string unit_types, valid_unit_symbols;
71126

72127
for( DisplayUnitType i = DisplayUnitType
73128
.DUT_METERS; i < n; ++i )
74129
{
130+
List<string> uts = new List<string>(
131+
map_dut_to_ut[i]
132+
.Select<UnitType, string>(
133+
u => u.ToString().Substring( 3 ) ) );
134+
135+
int m = uts.Count;
136+
137+
unit_types = 4 > m
138+
? string.Join( ", ", uts )
139+
: string.Format( "{0}, {1} and {2} more",
140+
uts[0], uts[1], m - 2 );
141+
75142
valid_unit_symbols = string.Join( ", ",
76143
FormatOptions.GetValidUnitSymbols( i )
77144
.Select<UnitSymbolType, string>(
78145
u => Util.UnitSymbolTypeString( u ) ) );
79146

80-
Debug.Print( "{0,6} - {1}: {2}",
147+
Debug.Print( "{0,6} - {1} - {2}: {3}",
81148
Util.DisplayUnitTypeAbbreviation[(int) i],
82149
LabelUtils.GetLabelFor( i ),
150+
unit_types,
151+
//i
83152
//UnitFormatUtils.Format( UnitType. ???
84153
//UnitUtils.ConvertFromInternalUnits( 1, i ),
85-
valid_unit_symbols,
86-
i );
154+
valid_unit_symbols );
87155
}
88156
return Result.Succeeded;
89157
}

BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
//
3232
// You can specify all the values or you can default the Revision and Build Numbers
3333
// by using the '*' as shown below:
34-
[assembly: AssemblyVersion( "2014.0.105.0" )]
35-
[assembly: AssemblyFileVersion( "2014.0.105.0" )]
34+
[assembly: AssemblyVersion( "2014.0.105.1" )]
35+
[assembly: AssemblyFileVersion( "2014.0.105.1" )]

0 commit comments

Comments
 (0)