From ce610fe8ecf8112295594a9dc6fc2eeea7122da1 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Fri, 14 Jun 2024 14:17:26 +0100 Subject: [PATCH] Back to old except for FootPrintRoof --- .../Helpers/ParameterValueExtractor.cs | 19 ++++++++++++++++--- .../Raw/BeamConversionToSpeckle.cs | 7 ++----- .../Raw/ColumnConversionToSpeckle.cs | 4 ++-- .../CeilingTopLevelConverterToSpeckle.cs | 7 ++----- ...ExtrusionRoofToSpeckleTopLevelConverter.cs | 8 ++------ .../FloorTopLevelConverterToSpeckle.cs | 8 ++------ ...FootPrintRoofToSpeckleTopLevelConverter.cs | 5 +++-- .../WallTopLevelConverterToSpeckle.cs | 12 +++--------- 8 files changed, 32 insertions(+), 38 deletions(-) diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs index 6d88c93049..db2685b51e 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Helpers/ParameterValueExtractor.cs @@ -160,15 +160,28 @@ public bool TryGetValueAsElementId( return GetValueGeneric(parameter, RevitStorageType.ElementId, (p) => p.AsElementId()); } - public IRevitLevel? GetValueAsRevitLevel(IRevitElement element, RevitBuiltInParameter builtInParameter) + public IRevitLevel GetValueAsRevitLevel(IRevitElement element, RevitBuiltInParameter builtInParameter) { if (!TryGetValueAsElementId(element, builtInParameter, out var elementId)) { - return null; + throw new SpeckleConversionException(); + } + + var paramElement = element.Document.GetElement(elementId); + return (paramElement?.ToLevel()).NotNull(); + } + + public bool TryGetValueAsRevitLevel(IRevitElement element, RevitBuiltInParameter builtInParameter, [NotNullWhen(true)] out IRevitLevel? revitLevel) + { + if (!TryGetValueAsElementId(element, builtInParameter, out var elementId)) + { + revitLevel = null; + return false; } var paramElement = element.Document.GetElement(elementId); - return paramElement?.ToLevel(); + revitLevel = paramElement?.ToLevel(); + return revitLevel is not null; } private TResult? GetValueGeneric( diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs index ae3227cd8a..59f790664f 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/BeamConversionToSpeckle.cs @@ -1,4 +1,4 @@ -using Objects; +using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Helpers; @@ -58,10 +58,7 @@ public SOBR.RevitBeam Convert(IRevitFamilyInstance target) target, RevitBuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM ); - if (level is not null) - { - speckleBeam.level = _levelConverter.Convert(level); - } + speckleBeam.level = _levelConverter.Convert(level); speckleBeam.displayValue = _displayValueExtractor.GetDisplayValue(target); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs index dc12c29082..7a2497d194 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/Raw/ColumnConversionToSpeckle.cs @@ -43,11 +43,11 @@ public SOBR.RevitColumn Convert(IRevitFamilyInstance target) new() { family = symbol.FamilyName, type = target.Document.GetElement(target.GetTypeId()).NotNull().Name }; var level = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.FAMILY_BASE_LEVEL_PARAM); - speckleColumn.level = _levelConverter.Convert(level.NotNull()); + speckleColumn.level = _levelConverter.Convert(level); var topLevel = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.FAMILY_TOP_LEVEL_PARAM); - speckleColumn.topLevel = _levelConverter.Convert(topLevel.NotNull()); + speckleColumn.topLevel = _levelConverter.Convert(topLevel); speckleColumn.baseOffset = _parameterValueExtractor.GetValueAsDouble( target, RevitBuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs index 249120378c..3dd7ed8cb6 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/CeilingTopLevelConverterToSpeckle.cs @@ -1,4 +1,4 @@ -using Objects; +using Objects; using Objects.BuiltElements.Revit; using Objects.Geometry; using Speckle.Converters.Common; @@ -60,10 +60,7 @@ public override RevitCeiling Convert(IRevitCeiling target) // but it is never being set. We should be setting it var level = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.LEVEL_PARAM); - if (level is not null) - { - speckleCeiling.level = _levelConverter.Convert(level); - } + speckleCeiling.level = _levelConverter.Convert(level); _parameterObjectAssigner.AssignParametersToBase(target, speckleCeiling); speckleCeiling.displayValue = _displayValueExtractor.GetDisplayValue(target); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs index cf75835d94..8dfeb7907a 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/ExtrusionRoofToSpeckleTopLevelConverter.cs @@ -1,4 +1,4 @@ -using Objects.BuiltElements.Revit.RevitRoof; +using Objects.BuiltElements.Revit.RevitRoof; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Extensions; @@ -57,11 +57,7 @@ public override RevitExtrusionRoof Convert(IRevitExtrusionRoof target) target, RevitBuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM ); - if (level is not null) - { - speckleExtrusionRoof.level = _levelConverter.Convert(level); - } - + speckleExtrusionRoof.level = _levelConverter.Convert(level); speckleExtrusionRoof.outline = _modelCurveArrayConverter.Convert(target.GetProfile()); var elementType = target.Document.GetElement(target.GetTypeId()).NotNull().ToType().NotNull(); diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs index 926a471b19..eb292cae5b 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FloorTopLevelConverterToSpeckle.cs @@ -1,4 +1,4 @@ -using Objects; +using Objects; using Speckle.Converters.Common; using Speckle.Converters.Common.Objects; using Speckle.Converters.RevitShared.Helpers; @@ -63,11 +63,7 @@ public override SOBR.RevitFloor Convert(IRevitFloor target) } var level = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.LEVEL_PARAM); - if (level is not null) - { - speckleFloor.level = _levelConverter.Convert(level); - } - + speckleFloor.level = _levelConverter.Convert(level.NotNull()); speckleFloor.structural = _parameterValueExtractor.GetValueAsBool(target, RevitBuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL) ?? false; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs index 5a51d40f28..78600db3ff 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/FootPrintRoofToSpeckleTopLevelConverter.cs @@ -44,7 +44,8 @@ public override RevitFootprintRoof Convert(IRevitFootPrintRoof target) var baseLevel = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.ROOF_BASE_LEVEL_PARAM); // We don't currently validate the success of this TryGet, it is assumed some Roofs don't have a top-level. - var topLevel = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.ROOF_UPTO_LEVEL_PARAM); + IRevitLevel? topLevel; + _parameterValueExtractor.TryGetValueAsRevitLevel(target, RevitBuiltInParameter.ROOF_UPTO_LEVEL_PARAM, out topLevel); //POC: CNX-9403 can be null if the sides have different slopes. //We currently don't validate the success or failure of this TryGet as it's not necessary, but will be once we start the above ticket. @@ -53,7 +54,7 @@ public override RevitFootprintRoof Convert(IRevitFootPrintRoof target) RevitFootprintRoof speckleFootprintRoof = new() { - level = _levelConverter.Convert(baseLevel.NotNull()), + level = _levelConverter.Convert(baseLevel), cutOffLevel = topLevel is not null ? _levelConverter.Convert(topLevel) : null, slope = slope }; diff --git a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs index aa8d4e8002..e9a0dbafc1 100644 --- a/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs +++ b/DUI3-DX/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/WallTopLevelConverterToSpeckle.cs @@ -1,4 +1,4 @@ -using Speckle.Converters.Common.Objects; +using Speckle.Converters.Common.Objects; using Speckle.Converters.Common; using Objects; using Speckle.Converters.RevitShared.Helpers; @@ -74,16 +74,10 @@ private void AssignSpecificParameters(IRevitWall target, RevitWall speckleWall) speckleWall.baseLine = _curveConverter.Convert(locationCurve.Curve); var level = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.WALL_BASE_CONSTRAINT); - if (level is not null) - { - speckleWall.level = _levelConverter.Convert(level); - } + speckleWall.level = _levelConverter.Convert(level); var topLevel = _parameterValueExtractor.GetValueAsRevitLevel(target, RevitBuiltInParameter.WALL_BASE_CONSTRAINT); - if (topLevel is not null) - { - speckleWall.topLevel = _levelConverter.Convert(topLevel); - } + speckleWall.topLevel = _levelConverter.Convert(topLevel); // POC : what to do if these parameters are unset (instead of assigning default) _ = _parameterValueExtractor.TryGetValueAsDouble(