Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void TestElementParameterInfoService(string vimFilePath)
var elementLevelInfos = infos.ElementLevelInfos;
var elementMeasureInfos = infos.ElementMeasureInfos;
var elementIfcInfos = infos.ElementIfcInfos;
var parameterMeasureTypes = infos.ParameterMeasureTypes;
var parameterMeasureInfos = infos.ParameterMeasureInfos;

var validationTableSet = new EntityTableSet(
vimFileInfo,
Expand All @@ -49,7 +49,7 @@ public static void TestElementParameterInfoService(string vimFilePath)
Assert.AreEqual(elementInstanceCount, elementIfcInfos.Length);

var parameterCount = validationTableSet.ParameterTable.RowCount;
Assert.AreEqual(parameterCount, parameterMeasureTypes.Length);
Assert.AreEqual(parameterCount, parameterMeasureInfos.Length);

var familyInstanceElementMap = validationTableSet.ElementIndexMaps.FamilyInstanceIndexFromElementIndex;

Expand Down
1,202 changes: 1,202 additions & 0 deletions src/cs/vim/Vim.Format/CategoryDomain.cs

Large diffs are not rendered by default.

122 changes: 122 additions & 0 deletions src/cs/vim/Vim.Format/ElementDomain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System.Collections.Generic;
using System.Diagnostics;
using Vim.Format.ObjectModel;

namespace Vim.Format
{
public enum ElementDomainEnum
{
Conceptual = 0,
PhysicalVisible = 10,
PhysicalHidden = 11,
PhysicalNotInstanced = 12,
Topography = 20,
Group = 30,
Rooms = 40,
System = 50,
LinkVisible = 60,
LinkHidden = 61,
Annotation = 70,
Symbol = 80
}

public static class ElementDomainEnumExtensions
{
public static string ToDisplayString(this ElementDomainEnum e)
{
switch (e)
{
case ElementDomainEnum.PhysicalVisible: return "Physical-Visible";
case ElementDomainEnum.PhysicalHidden: return "Physical-Hidden";
case ElementDomainEnum.PhysicalNotInstanced: return "Physical-NotInstanced";
case ElementDomainEnum.LinkVisible: return "Link-Visible";
case ElementDomainEnum.LinkHidden: return "Link-Hidden";
default: return e.ToString("G");
}
}
}

/// <summary>
/// The ElementDomain is a labeling of each element which facilitates the filtering of large lists of elements.
/// </summary>
public static class ElementDomain
{
/// <summary>
/// Returns an array aligned 1:1 with the element table to identify the ElementDomain.
/// </summary>
public static ElementDomainEnum[] GetElementDomains(
ElementTable elementTable,
CategoryTable categoryTable,
ElementKind[] elementKinds,
bool[] elementIsVisibleIn3dView)
{
var categoryDomains = CategoryDomain.GetCategoryDomainMap();

var elementDomains = new ElementDomainEnum[elementTable.RowCount];

for (var i = 0; i < elementDomains.Length; ++i)
elementDomains[i] = GetElementDomain(i, elementTable, categoryTable, elementKinds, elementIsVisibleIn3dView, categoryDomains);

return elementDomains;
}

public static ElementDomainEnum GetElementDomain(
int elementIndex,
ElementTable elementTable,
CategoryTable categoryTable,
ElementKind[] elementKinds,
bool[] elementIsVisibleIn3dView,
Dictionary<string, CategoryDomainEnum> categoryDomains)
{
var elementKind = elementKinds[elementIndex];

// Family and FamilyType elements are relegated to the conceptual element domain.
if (elementKind == ElementKind.Family || elementKind == ElementKind.FamilyType)
return ElementDomainEnum.Conceptual;

// Elements which are neither Family or FamilyType are labeled based on the category domain.
var categoryIndex = elementTable.GetCategoryIndex(elementIndex);
var builtInCategory = categoryTable.GetBuiltInCategory(categoryIndex);

var hasCategoryDomain = categoryDomains.TryGetValue(builtInCategory, out var categoryDomain);
if (!hasCategoryDomain)
{
// Special case: if the VIM file was sourced from IFC (or some source other than Revit),
// it probably won't have category domain. In this case, we use the ElementKind.FamilyInstance
// to determine whether the element domain is actually conceptual.
return elementKind is ElementKind.FamilyInstance
? GetPhysicalDomain(elementIndex, elementIsVisibleIn3dView)
: ElementDomainEnum.Conceptual;
}

switch (categoryDomain)
{
case CategoryDomainEnum.Conceptual: return ElementDomainEnum.Conceptual;
case CategoryDomainEnum.Physical:
return elementKind is ElementKind.FamilyInstance
? GetPhysicalDomain(elementIndex, elementIsVisibleIn3dView)
: ElementDomainEnum.PhysicalNotInstanced;
case CategoryDomainEnum.Topography: return ElementDomainEnum.Topography;
case CategoryDomainEnum.Group: return ElementDomainEnum.Group;
case CategoryDomainEnum.Rooms: return ElementDomainEnum.Rooms;
case CategoryDomainEnum.System: return ElementDomainEnum.System;
case CategoryDomainEnum.Link: return GetLinkDomain(elementIndex, elementIsVisibleIn3dView);
case CategoryDomainEnum.Annotation: return ElementDomainEnum.Annotation;
case CategoryDomainEnum.Symbol: return ElementDomainEnum.Symbol;
default:
Debug.Fail($"Unknown CategoryDomainEnum {categoryDomain:G}");
return ElementDomainEnum.Conceptual;
}
}

public static ElementDomainEnum GetPhysicalDomain(int elementIndex, bool[] elementIsVisibleIn3dView)
=> elementIsVisibleIn3dView[elementIndex]
? ElementDomainEnum.PhysicalVisible
: ElementDomainEnum.PhysicalHidden;

public static ElementDomainEnum GetLinkDomain(int elementIndex, bool[] elementIsVisibleIn3dView)
=> elementIsVisibleIn3dView[elementIndex]
? ElementDomainEnum.LinkVisible
: ElementDomainEnum.LinkHidden;
}
}
27 changes: 23 additions & 4 deletions src/cs/vim/Vim.Format/ElementParameterInfo/ElementMeasureInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,31 @@ public int GetElementIndexOrNone()
=> Element.IndexOrDefault();

public double? Angle { get; set; }
public bool AngleIsRevitBuiltIn { get; set; }

public double? Slope { get; set; }
public bool SlopeIsRevitBuiltIn { get; set; }

public double? Length { get; set; }
public bool LengthIsRevitBuiltIn { get; set; }

public double? Width { get; set; }
public bool WidthIsRevitBuiltIn { get; set; }

public double? Height { get; set; }
public bool HeightIsRevitBuiltIn { get; set; }

public double? Area { get; set; }
public bool AreaIsRevitBuiltIn { get; set; }

public double? Volume { get; set; }
public bool VolumeIsRevitBuiltIn { get; set; }

public double? Depth { get; set; }
public bool DepthIsRevitBuiltIn { get; set; }

public double? Diameter { get; set; }
public bool DiameterIsRevitBuiltIn { get; set; }

/// <summary>
/// Constructor
Expand All @@ -45,7 +54,7 @@ public ElementMeasureInfo(
Element element,
ElementTable elementTable,
ParameterTable parameterTable,
MeasureType[] parameterMeasureInfos)
ParameterMeasureInfo[] parameterMeasureInfos)
{
Element = element;

Expand All @@ -68,44 +77,54 @@ public ElementMeasureInfo(

private void ReadParameters(
ParameterTable parameterTable,
MeasureType[] parameterMeasureInfos,
ParameterMeasureInfo[] parameterMeasureInfos,
IReadOnlyList<int> parameterIndices)
{
foreach (var parameterIndex in parameterIndices)
{
var mt = parameterMeasureInfos[parameterIndex];
var pmi = parameterMeasureInfos[parameterIndex];
var measureType = pmi.MeasureType;

var (nativeValue, _) = Parameter.SplitValues(parameterTable.Column_Value[parameterIndex]);
var parsed = Parameter.ParseNativeValueAsDouble(nativeValue);

switch (mt)
switch (measureType)
{
case MeasureType.Angle:
Angle = parsed;
AngleIsRevitBuiltIn = pmi.IsRevitBuiltIn;
break;
case MeasureType.Slope:
Slope = parsed;
SlopeIsRevitBuiltIn = pmi.IsRevitBuiltIn;
break;
case MeasureType.Length:
Length = parsed;
LengthIsRevitBuiltIn = pmi.IsRevitBuiltIn;
break;
case MeasureType.Width:
Width = parsed;
WidthIsRevitBuiltIn = pmi.IsRevitBuiltIn;
break;
case MeasureType.Height:
Height = parsed;
HeightIsRevitBuiltIn = pmi.IsRevitBuiltIn;
break;
case MeasureType.Area:
Area = parsed;
AreaIsRevitBuiltIn = pmi.IsRevitBuiltIn;
break;
case MeasureType.Volume:
Volume = parsed;
VolumeIsRevitBuiltIn = pmi.IsRevitBuiltIn;
break;
case MeasureType.Depth:
Depth = parsed;
DepthIsRevitBuiltIn = pmi.IsRevitBuiltIn;
break;
case MeasureType.Diameter:
Diameter = parsed;
DiameterIsRevitBuiltIn = pmi.IsRevitBuiltIn;
break;
case MeasureType.Unknown:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public class ElementParameterInfo
public FamilyTypeUniformatInfo[] FamilyTypeUniformatInfos { get; set; }

/// <summary>
/// An array of MeasureType values representing the measure types of each Parameter.
/// An array of ParameterMeasureInfos representing the measure types of each Parameter.
/// Items in this array are aligned to the Parameter table.
/// </summary>
public MeasureType[] ParameterMeasureTypes { get; set; }
public ParameterMeasureInfo[] ParameterMeasureInfos { get; set; }
}

public static class ElementParameterInfoService
Expand Down Expand Up @@ -136,9 +136,9 @@ public static ElementParameterInfo GetElementParameterInfos(
levelInfoMap,
levelInfoByBimDocumentIndex);

var parameterMeasureTypes = CreateParameterMeasureTypes(parameterTable, descriptorTable);
var parameterMeasureInfos = CreateParameterMeasureInfos(parameterTable, descriptorTable);

var elementMeasureInfos = CreateElementMeasureInfos(elementTable, parameterTable, parameterMeasureTypes);
var elementMeasureInfos = CreateElementMeasureInfos(elementTable, parameterTable, parameterMeasureInfos);

var elementOffsetInfos = CreateElementOffsetInfos(elementTable, parameterTable, elementIndexMaps);

Expand All @@ -154,7 +154,7 @@ public static ElementParameterInfo GetElementParameterInfos(
ElementLevelInfos = elementLevelInfos,
ElementMeasureInfos = elementMeasureInfos,
ElementOffsetInfos = elementOffsetInfos,
ParameterMeasureTypes = parameterMeasureTypes,
ParameterMeasureInfos = parameterMeasureInfos,
ElementIfcInfos = elementIfcInfos,
FamilyOmniClassInfos = familyOmniClassInfos,
FamilyTypeUniformatInfos = familyTypeUniformatInfos,
Expand Down Expand Up @@ -259,7 +259,7 @@ private static ElementLevelInfo[] CreateElementLevelInfos(
.ToArray();
}

public static MeasureType[] CreateParameterMeasureTypes(
public static ParameterMeasureInfo[] CreateParameterMeasureInfos(
ParameterTable parameterTable,
ParameterDescriptorTable parameterDescriptorTable)
=> parameterTable.Column_ParameterDescriptorIndex
Expand All @@ -268,17 +268,17 @@ public static MeasureType[] CreateParameterMeasureTypes(
{
var parameterDescriptorNameLowerInvariant = parameterDescriptorTable.GetName(pdi).ToLowerInvariant();
var parameterDescriptorGuid = parameterDescriptorTable.GetGuid(pdi);
return ParameterMeasureInfo.ParseMeasureType(parameterDescriptorNameLowerInvariant, parameterDescriptorGuid);
return ParameterMeasureInfo.ParseMeasureInfo(parameterDescriptorNameLowerInvariant, parameterDescriptorGuid);
})
.ToArray();

public static ElementMeasureInfo[] CreateElementMeasureInfos(
ElementTable elementTable,
ParameterTable parameterTable,
MeasureType[] parameterMeasureTypes)
ParameterMeasureInfo[] parameterMeasureInfos)
=> elementTable
.AsParallel()
.Select(e => new ElementMeasureInfo(e, elementTable, parameterTable, parameterMeasureTypes))
.Select(e => new ElementMeasureInfo(e, elementTable, parameterTable, parameterMeasureInfos))
.ToArray();

public static ElementOffsetInfo[] CreateElementOffsetInfos(
Expand Down
23 changes: 16 additions & 7 deletions src/cs/vim/Vim.Format/ElementParameterInfo/ParameterMeasureInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,17 @@ public enum MeasureType
// - *DO NOT CHANGE THE ACTUAL ENUM VALUES*
}

public static class ParameterMeasureInfo
public class ParameterMeasureInfo
{
public MeasureType MeasureType { get; }
public bool IsRevitBuiltIn { get; }

public ParameterMeasureInfo(MeasureType measureType, bool isRevitBuiltIn)
{
MeasureType = measureType;
IsRevitBuiltIn = isRevitBuiltIn;
}

/// <summary>
/// Maps the lowercase parameter name to the MeasureType.
/// </summary>
Expand All @@ -57,15 +66,15 @@ public static class ParameterMeasureInfo
// })
// .ToArray();

public static MeasureType ParseMeasureType(string parameterDescriptorNameLowerInvariant, string parameterDescriptorGuid)
public static ParameterMeasureInfo ParseMeasureInfo(string parameterDescriptorNameLowerInvariant, string parameterDescriptorGuid)
{
// NOTE: parameterDescriptorGuid is either the Revit built-in ID (if the parameter is built-in), or a guid (if the parameter is shared).
if (BuiltInIdToMeasureTypeMap.TryGetValue(parameterDescriptorGuid, out var measureType))
return measureType;
if (RevitBuiltInIdToMeasureTypeMap.TryGetValue(parameterDescriptorGuid, out var measureType))
return new ParameterMeasureInfo(measureType, true);

// Compare the input descriptor name to the known mapping
if (NameLowerInvariantToMeasureTypeMap.TryGetValue(parameterDescriptorNameLowerInvariant, out measureType))
return measureType;
return new ParameterMeasureInfo(measureType, false);

// Fall back to a string comparison to catch any localized parameter descriptor names which either start or end with the key followed by a space and digits,
// for example: "Length of Beam" or "Pipe Length 1"
Expand All @@ -82,7 +91,7 @@ public static MeasureType ParseMeasureType(string parameterDescriptorNameLowerIn
// return candidateMeasureType;
//}

return MeasureType.Unknown;
return new ParameterMeasureInfo(MeasureType.Unknown, false);
}

public static void GetQuantityOrDisplayValue(
Expand Down Expand Up @@ -154,7 +163,7 @@ public static void GetQuantityOrDisplayValue(
/// <summary>
/// Maps the built-in parameter Revit ID to the MeasureType
/// </summary>
public static readonly Dictionary<string, MeasureType> BuiltInIdToMeasureTypeMap = new Dictionary<string, MeasureType>()
public static readonly Dictionary<string, MeasureType> RevitBuiltInIdToMeasureTypeMap = new Dictionary<string, MeasureType>()
{
{ "-1001817", MeasureType.Angle }, // PROFILE_ANGLE, "Angle"
{ "-1001826", MeasureType.Angle }, // PROFILE1_ANGLE, "Angle"
Expand Down
Loading
Loading