Skip to content

Commit

Permalink
Use ProxyMap class that is source generated (#3507)
Browse files Browse the repository at this point in the history
* 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?

* Bumping proxy API and using source gen ProxyMap

* fmt

* putting root back

* use IProxyMapper in root converter

* bump host apis

* revert registration change

* remove sendselection
  • Loading branch information
adamhathcock authored Jun 14, 2024
1 parent 76c6aba commit a18cba1
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 121 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Speckle.Connectors.Revit.HostApp;
using Speckle.Connectors.Revit.Operations.Send;
using Speckle.Connectors.Revit.Plugin;
using Speckle.Connectors.Revit2023.Converters;
using Speckle.Connectors.RevitShared.Helpers;
using Speckle.Connectors.Utils;
using Speckle.Connectors.Utils.Builders;
Expand Down Expand Up @@ -73,6 +72,5 @@ public void Load(SpeckleContainerBuilder builder)

// register send conversion cache
builder.AddSingleton<ISendConversionCache, SendConversionCache>();
builder.AddSingleton<IProxyMap, ProxyMap>();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public RootObjectBuilderResult Build(
throw new SpeckleException("Family Environment documents are not supported.");
}

var revitElements = new List<Element>(); // = _contextStack.Current.Document.GetElements(sendSelection.SelectedItems).ToList();
var revitElements = new List<Element>();

foreach (var id in objects)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ public void Load(SpeckleContainerBuilder builder)
builder.AddScoped<IHostedElementConversionToSpeckle, HostedElementConversionToSpeckle>();
builder.AddScoped<IParameterObjectAssigner, ParameterObjectAssigner>();
builder.AddScoped<ISlopeArrowExtractor, SlopeArrowExtractor>();
builder.AddScoped<SendSelection>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Speckle.Revit2023.Api" Version="0.1.1-preview.0.20" />
<PackageReference Include="Speckle.Revit2023.Api" Version="0.1.1-preview.0.22" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Sdk\Speckle.Converters.Common.DependencyInjection\Speckle.Converters.Common.DependencyInjection.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0"/>
<PackageReference Include="coverlet.collector" Version="6.0.2"/>
<PackageReference Include="Speckle.Revit2023.Interfaces" Version="0.1.1-preview.0.20" />
<PackageReference Include="Speckle.Revit2023.Interfaces" Version="0.1.1-preview.0.22" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
},
"Speckle.Revit2023.Interfaces": {
"type": "Direct",
"requested": "[0.1.1-preview.0.20, )",
"resolved": "0.1.1-preview.0.20",
"contentHash": "L/8btGlDejt6OCe8Lee05N3ztKV+pz24WAU9fwXRHEeWMgSe+bqq477Jmk641QFcKmcWK25XJlprlHiCh4pAdQ=="
"requested": "[0.1.1-preview.0.22, )",
"resolved": "0.1.1-preview.0.22",
"contentHash": "Z6bfEIKFYJtXPjHQYlGBjiQLekVOU7L//H9gaQIw3ba9jqJeYHx5AV0z6S83g04eGBKkNJC6EwBr+fspsK0f+w=="
},
"Castle.Core": {
"type": "Transitive",
Expand Down Expand Up @@ -499,7 +499,7 @@
"dependencies": {
"Speckle.Autofac": "[2.0.999-local, )",
"Speckle.Objects": "[2.0.999-local, )",
"Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.20, )"
"Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.22, )"
}
},
"speckle.converters.common.dependencyinjection": {
Expand All @@ -513,7 +513,7 @@
"type": "Project",
"dependencies": {
"Speckle.Converters.Common": "[2.0.999-local, )",
"Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.20, )"
"Speckle.Revit2023.Interfaces": "[0.1.1-preview.0.22, )"
}
},
"Speckle.Core": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Import Project="..\Speckle.Converters.RevitShared\Speckle.Converters.RevitShared.projitems" Label="Shared" />

<ItemGroup>
<PackageReference Include="Speckle.Revit2023.Interfaces" Version="0.1.1-preview.0.20" />
<PackageReference Include="Speckle.Revit2023.Interfaces" Version="0.1.1-preview.0.22" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,3 @@ public double GetSlopeArrowHeadOffset(IRevitModelLine slopeArrow, double tailOff
return headOffset;
}
}

// POC: why do we need this send selection?
// why does conversion need to know about selection in this way?
public class SendSelection
{
private readonly HashSet<string> _selectedItemIds;

public SendSelection(IEnumerable<string> selectedItemIds)
{
_selectedItemIds = new HashSet<string>(selectedItemIds);
}

public bool Contains(string elementId) => _selectedItemIds.Contains(elementId);

public IReadOnlyCollection<string> SelectedItems => _selectedItemIds.ToList().AsReadOnly();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using Speckle.Converters.Common;
using Speckle.InterfaceGenerator;
using Speckle.Revit.Interfaces;
Expand Down Expand Up @@ -32,7 +32,6 @@ public class ReferencePointConverter : IReferencePointConverter
private readonly IRevitTransformUtils _transformUtils;
private readonly IRevitFilterFactory _revitFilterFactory;
private readonly IRevitXYZUtils _revitXyzUtils;
private readonly IProxyMap _proxyMap;

private readonly Dictionary<string, IRevitTransform> _docTransforms = new();

Expand All @@ -41,16 +40,14 @@ public ReferencePointConverter(
IRevitConversionSettings revitSettings,
IRevitFilterFactory revitFilterFactory,
IRevitTransformUtils transformUtils,
IRevitXYZUtils revitXyzUtils,
IProxyMap proxyMap
IRevitXYZUtils revitXyzUtils
)
{
_contextStack = contextStack;
_revitSettings = revitSettings;
_revitFilterFactory = revitFilterFactory;
_transformUtils = transformUtils;
_revitXyzUtils = revitXyzUtils;
_proxyMap = proxyMap;
}

// POC: the original allowed for the document to be passed in
Expand Down Expand Up @@ -92,7 +89,7 @@ public IRevitTransform GetReferencePointTransform(string referencePointSetting)
// POC: bogus disposal below
var points = _revitFilterFactory
.CreateFilteredElementCollector(_contextStack.Current.Document)
.OfClass<IRevitBasePoint>(_proxyMap)
.OfClass<IRevitBasePoint>()
.ToList();

var projectPoint = NotNullExtensions.NotNull(points.FirstOrDefault(o => o.IsShared == false), "No projectPoint");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace Speckle.Converters.Common;
public class RootToSpeckleConverter : IRootToSpeckleConverter
{
private readonly IFactory<IToSpeckleTopLevelConverter> _toSpeckle;
private readonly IProxyMap _proxyMap;
private readonly IProxyMapper _proxyMapper;

public RootToSpeckleConverter(IFactory<IToSpeckleTopLevelConverter> toSpeckle, IProxyMap proxyMap)
public RootToSpeckleConverter(IFactory<IToSpeckleTopLevelConverter> toSpeckle, IProxyMapper proxyMapper)
{
_toSpeckle = toSpeckle;
_proxyMap = proxyMap;
_proxyMapper = proxyMapper;
}

public Base Convert(object target)
{
Type revitType = target.GetType();
var wrapper = _proxyMap.WrapIfExists(revitType, target);
var wrapper = _proxyMapper.WrapIfExists(revitType, target);
if (wrapper == null)
{
throw new NotSupportedException($"No wrapper found for Revit type: {revitType.Name}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Speckle.Revit2023.Interfaces" Version="0.1.1-preview.0.20" />
<PackageReference Include="Speckle.Revit2023.Interfaces" Version="0.1.1-preview.0.22" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Sdk\Speckle.Autofac\Speckle.Autofac.csproj"/>
Expand Down

0 comments on commit a18cba1

Please sign in to comment.