-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert revit converters to use proxies for unit testing (#3501)
* Initial commit from converter-tests * tests now run * adding more to proxy map * switch to FluentAssertions * fix IRevitLevel conversions * more cast handling * use proxymap for ofclass * update revit interfaces * fmt * add more proxies * better handling for wrapped types * fix the RevitContext * inject interfaces * convert to new way of casting * update and rejigger dependencies * handle null elements * proxy map is also proxy aware * fmt * change namespaces * updates to proxies * more cast changes * another cast issue fixed * update nugets * fmt * add System.IO to make CI happy?
- Loading branch information
1 parent
6b767fe
commit 76c6aba
Showing
109 changed files
with
2,070 additions
and
1,530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitBaseBinding.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/DependencyInjection/ProxyMap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.Collections.Concurrent; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Speckle.Revit.Api; | ||
using Speckle.Revit.Interfaces; | ||
|
||
namespace Speckle.Connectors.Revit2023.Converters; | ||
|
||
[SuppressMessage("Performance", "CA1810:Initialize reference type static fields inline")] | ||
public class ProxyMap : IProxyMap | ||
{ | ||
private static readonly ConcurrentDictionary<Type, Type> s_revitToInterfaceMap = new(); | ||
private static readonly ConcurrentDictionary<Type, Type> s_proxyToInterfaceMap = new(); | ||
private static readonly ConcurrentDictionary<Type, Type> s_interfaceToRevit = new(); | ||
private static readonly ConcurrentDictionary<Type, Func<object, object>> s_proxyFactory = new(); | ||
|
||
[SuppressMessage("Maintainability", "CA1506:Avoid excessive class coupling")] | ||
static ProxyMap() | ||
{ | ||
Add<DB.Element, IRevitElement, ElementProxy>(x => new ElementProxy(x)); | ||
Add<DB.FamilyInstance, IRevitFamilyInstance, FamilyInstanceProxy>(x => new FamilyInstanceProxy(x)); | ||
Add<DB.Curve, IRevitCurve, CurveProxy>(x => new CurveProxy(x)); | ||
Add<DB.BoundarySegment, IRevitBoundarySegment, BoundarySegmentProxy>(x => new BoundarySegmentProxy(x)); | ||
Add<DB.Level, IRevitLevel, LevelProxy>(x => new LevelProxy(x)); | ||
Add<DB.Location, IRevitLocation, LocationProxy>(x => new LocationProxy(x)); | ||
Add<DB.Material, IRevitMaterial, MaterialProxy>(x => new MaterialProxy(x)); | ||
Add<DB.ModelCurveArray, IRevitModelCurveArray, ModelCurveArrayProxy>(x => new ModelCurveArrayProxy(x)); | ||
Add<DB.ModelCurveArrArray, IRevitModelCurveArrArray, ModelCurveArrArrayProxy>(x => new ModelCurveArrArrayProxy(x)); | ||
Add<DB.Parameter, IRevitParameter, ParameterProxy>(x => new ParameterProxy(x)); | ||
Add<DB.BasePoint, IRevitBasePoint, BasePointProxy>(x => new BasePointProxy(x)); | ||
Add<DB.Wall, IRevitWall, WallProxy>(x => new WallProxy(x)); | ||
Add<DB.Panel, IRevitPanel, PanelProxy>(x => new PanelProxy(x)); | ||
Add<DB.Floor, IRevitFloor, FloorProxy>(x => new FloorProxy(x)); | ||
Add<DB.Ceiling, IRevitCeiling, CeilingProxy>(x => new CeilingProxy(x)); | ||
Add<DB.FootPrintRoof, IRevitFootPrintRoof, FootPrintRoofProxy>(x => new FootPrintRoofProxy(x)); | ||
Add<DB.ModelLine, IRevitModelLine, ModelLineProxy>(x => new ModelLineProxy(x)); | ||
Add<DB.RoofBase, IRevitRoofBase, RoofBaseProxy>(x => new RoofBaseProxy(x)); | ||
} | ||
|
||
private static void Add<T, TInterface, TProxy>(Func<T, TProxy> f) | ||
where T : class | ||
where TInterface : notnull | ||
where TProxy : TInterface | ||
{ | ||
s_revitToInterfaceMap.TryAdd(typeof(T), typeof(TInterface)); | ||
s_proxyToInterfaceMap.TryAdd(typeof(TProxy), typeof(TInterface)); | ||
s_proxyFactory.TryAdd(typeof(TInterface), w => f((T)w)); | ||
s_interfaceToRevit.TryAdd(typeof(TInterface), typeof(T)); | ||
} | ||
|
||
public Type? GetMappedTypeFromHostType(Type type) | ||
{ | ||
if (s_revitToInterfaceMap.TryGetValue(type, out var t)) | ||
{ | ||
return t; | ||
} | ||
return null; | ||
} | ||
|
||
public Type? GetMappedTypeFromProxyType(Type type) | ||
{ | ||
if (s_proxyToInterfaceMap.TryGetValue(type, out var t)) | ||
{ | ||
return t; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public Type? GetHostTypeFromMappedType(Type type) | ||
{ | ||
if (s_interfaceToRevit.TryGetValue(type, out var t)) | ||
{ | ||
return t; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public object CreateProxy(Type type, object toWrap) => s_proxyFactory[type](toWrap); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/GlobalUsings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using DB = Autodesk.Revit.DB; |
4 changes: 2 additions & 2 deletions
4
...rters.RevitShared/Helpers/RevitContext.cs → ...ctors.RevitShared/Helpers/RevitContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...DX/Connectors/Revit/Speckle.Connectors.RevitShared/Helpers/RevitConversionContextStack.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Autodesk.Revit.DB; | ||
using Speckle.Converters.Common; | ||
using Speckle.Revit.Api; | ||
using Speckle.Revit.Interfaces; | ||
|
||
namespace Speckle.Connectors.RevitShared.Helpers; | ||
|
||
[System.Diagnostics.CodeAnalysis.SuppressMessage( | ||
"Naming", | ||
"CA1711:Identifiers should not have incorrect suffix", | ||
Justification = "See base class justification" | ||
)] | ||
// POC: so this should *probably* be Document and NOT UI.UIDocument, the former is Conversion centric | ||
// and the latter is more for connector | ||
public class RevitConversionContextStack | ||
: ConversionContextStack<IRevitDocument, IRevitForgeTypeId>, | ||
IConversionContextStack<IRevitDocument, IRevitForgeTypeId> | ||
{ | ||
public RevitConversionContextStack(RevitContext context, IHostToSpeckleUnitConverter<IRevitForgeTypeId> unitConverter) | ||
: base( | ||
// POC: we probably should not get here without a valid document | ||
// so should this perpetuate or do we assume this is valid? | ||
// relting on the context.UIApplication?.ActiveUIDocument is not right | ||
// this should be some IActiveDocument I suspect? | ||
new DocumentProxy( | ||
context.UIApplication?.ActiveUIDocument?.Document | ||
?? throw new SpeckleConversionException("Active UI document could not be determined") | ||
), | ||
new ForgeTypeIdProxy( | ||
context.UIApplication.ActiveUIDocument.Document.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId() | ||
), | ||
unitConverter | ||
) { } | ||
|
||
ContextWrapper<IRevitDocument, IRevitForgeTypeId> IConversionContextStack<IRevitDocument, IRevitForgeTypeId>.Push( | ||
string speckleUnit | ||
) => throw new NotImplementedException(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.