Skip to content

Commit

Permalink
implemented MapDutToUt dictionary mapping each DisplayUnitType to a l…
Browse files Browse the repository at this point in the history
…ist of UnitType values that it may be used for by inverting the result of the UnitUtils.GetValidDisplayUnits method
  • Loading branch information
Jeremy Tammik committed Nov 4, 2013
1 parent 825014f commit 2574b5d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
76 changes: 72 additions & 4 deletions BuildingCoder/BuildingCoder/CmdDutAbbreviation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#region Namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
Expand All @@ -18,6 +19,58 @@

namespace BuildingCoder
{
/// <summary>
/// Map each DisplayUnitType to a list of all the
/// UnitType values that it might be used for, e.g.
/// Meters is mapped to the following 21 values:
/// Length, SheetLength, HVAC_DuctSize, HVAC_Roughness,
/// PipeSize, Piping_Roughness, WireSize, DecSheetLength,
/// Electrical_CableTraySize, Electrical_ConduitSize,
/// Reinforcement_Length, HVAC_DuctInsulationThickness,
/// HVAC_DuctLiningThickness, PipeInsulationThickness,
/// Bar_Diameter, Crack_Width, Displacement_Deflection,
/// Reinforcement_Cover, Reinforcement_Spacing,
/// Section_Dimension, Section_Property.
/// </summary>
class MapDutToUt : Dictionary<DisplayUnitType, List<UnitType>>
{
public MapDutToUt()
{
IList<DisplayUnitType> duts;

Array a = Enum.GetValues( typeof( UnitType ) );

foreach( UnitType ut in a )
{
// Skip the UT_Undefined and UT_Custom entries;
// GetValidDisplayUnits throws ArgumentException
// on them, saying "unitType is an invalid unit
// type. See UnitUtils.IsValidUnitType() and
// UnitUtils.GetValidUnitTypes()."

if( UnitType.UT_Undefined == ut
|| UnitType.UT_Custom == ut )
{
continue;
}

duts = UnitUtils.GetValidDisplayUnits( ut );

foreach( DisplayUnitType dut in duts )
{
//Debug.Assert( !ContainsKey( dut ),
// "unexpected duplicate DisplayUnitType key" );

if( !ContainsKey( dut ) )
{
Add( dut, new List<UnitType>( 1 ) );
}
this[dut].Add( ut );
}
}
}
}

[Transaction( TransactionMode.ReadOnly )]
class CmdDutAbbreviation : IExternalCommand
{
Expand Down Expand Up @@ -59,6 +112,8 @@ public Result Execute(
Debug.Assert( 26 == (int) DisplayUnitType.DUT_LITERS, _s );
#endregion // Assertions

MapDutToUt map_dut_to_ut = new MapDutToUt();

DisplayUnitType n
= DisplayUnitType.DUT_GALLONS_US;

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

string valid_unit_symbols;
string unit_types, valid_unit_symbols;

for( DisplayUnitType i = DisplayUnitType
.DUT_METERS; i < n; ++i )
{
List<string> uts = new List<string>(
map_dut_to_ut[i]
.Select<UnitType, string>(
u => u.ToString().Substring( 3 ) ) );

int m = uts.Count;

unit_types = 4 > m
? string.Join( ", ", uts )
: string.Format( "{0}, {1} and {2} more",
uts[0], uts[1], m - 2 );

valid_unit_symbols = string.Join( ", ",
FormatOptions.GetValidUnitSymbols( i )
.Select<UnitSymbolType, string>(
u => Util.UnitSymbolTypeString( u ) ) );

Debug.Print( "{0,6} - {1}: {2}",
Debug.Print( "{0,6} - {1} - {2}: {3}",
Util.DisplayUnitTypeAbbreviation[(int) i],
LabelUtils.GetLabelFor( i ),
unit_types,
//i
//UnitFormatUtils.Format( UnitType. ???
//UnitUtils.ConvertFromInternalUnits( 1, i ),
valid_unit_symbols,
i );
valid_unit_symbols );
}
return Result.Succeeded;
}
Expand Down
4 changes: 2 additions & 2 deletions BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion( "2014.0.105.0" )]
[assembly: AssemblyFileVersion( "2014.0.105.0" )]
[assembly: AssemblyVersion( "2014.0.105.1" )]
[assembly: AssemblyFileVersion( "2014.0.105.1" )]

0 comments on commit 2574b5d

Please sign in to comment.