-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert revit converters to use proxies for unit testing DUI3-149 #3501
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
8f181f0
Initial commit from converter-tests
adamhathcock 907e7ee
tests now run
adamhathcock f7de9ac
adding more to proxy map
adamhathcock b430010
switch to FluentAssertions
adamhathcock c95677e
fix IRevitLevel conversions
adamhathcock 4b5fbf2
more cast handling
adamhathcock 6153576
use proxymap for ofclass
adamhathcock 11e51de
update revit interfaces
adamhathcock 9895c11
fmt
adamhathcock 1ca2756
add more proxies
adamhathcock d5ef59c
better handling for wrapped types
adamhathcock 373a4da
fix the RevitContext
adamhathcock daaac4b
inject interfaces
adamhathcock 44cebf8
Merge remote-tracking branch 'origin/dui3/alpha' into convert-revit-c…
adamhathcock 9438634
convert to new way of casting
adamhathcock c9f4035
update and rejigger dependencies
adamhathcock d426b90
handle null elements
adamhathcock 09d1a43
proxy map is also proxy aware
adamhathcock 1e3df18
fmt
adamhathcock 5ff2481
change namespaces
adamhathcock 3e780ac
updates to proxies
adamhathcock 193bd20
Merge remote-tracking branch 'origin/dui3/alpha' into convert-revit-c…
adamhathcock e284981
more cast changes
adamhathcock 10e7114
another cast issue fixed
adamhathcock 041bb5c
update nugets
adamhathcock fd019d4
fmt
adamhathcock 18b4d98
add System.IO to make CI happy?
adamhathcock ba55c8b
Merge branch 'dui3/alpha' into convert-revit-converters
adamhathcock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is an initialisation thing. We may need to delay initialisation of the stack (and maybe the plugin in general) until we know the application has initialised and is no longer null.
If the UIApplication does not exist yet, we can't really do anything else from that point onwards. But I may not have the full picture about this.