From f53c2d6cc58c95eddabc287d0b045537d2ba279f Mon Sep 17 00:00:00 2001 From: root Date: Wed, 15 Jan 2025 13:40:45 +0000 Subject: [PATCH] Update ifc parser to use new nuget and ability to test --- .../ifc-dotnet/DummyServerObjectManager.cs | 43 ++++++++++++++ .../fileimport-service/ifc-dotnet/Program.cs | 56 ++++++++++++++++++- .../ifc-dotnet/ifc-converter.csproj | 2 +- 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 packages/fileimport-service/ifc-dotnet/DummyServerObjectManager.cs diff --git a/packages/fileimport-service/ifc-dotnet/DummyServerObjectManager.cs b/packages/fileimport-service/ifc-dotnet/DummyServerObjectManager.cs new file mode 100644 index 0000000000..25dd0df56f --- /dev/null +++ b/packages/fileimport-service/ifc-dotnet/DummyServerObjectManager.cs @@ -0,0 +1,43 @@ +using System.Text; +using Speckle.Sdk.Serialisation.V2; +using Speckle.Sdk.Serialisation.V2.Send; +using Speckle.Sdk.Transports; + +namespace Speckle.Converter; + +public class DummyServerObjectManager : IServerObjectManager +{ + public IAsyncEnumerable<(string, string)> DownloadObjects( + IReadOnlyCollection objectIds, + IProgress? progress, + CancellationToken cancellationToken + ) => throw new NotImplementedException(); + + public Task DownloadSingleObject( + string objectId, + IProgress? progress, + CancellationToken cancellationToken + ) => throw new NotImplementedException(); + + public Task> HasObjects( + IReadOnlyCollection objectIds, + CancellationToken cancellationToken + ) => Task.FromResult(objectIds.ToDictionary(id => id, id => false)); + + public Task UploadObjects( + IReadOnlyList objects, + bool compressPayloads, + IProgress? progress, + CancellationToken cancellationToken + ) + { + long totalBytes = 0; + foreach (var item in objects) + { + totalBytes += Encoding.Default.GetByteCount(item.Json.Value); + } + + progress?.Report(new(ProgressEvent.UploadBytes, totalBytes, totalBytes)); + return Task.CompletedTask; + } +} diff --git a/packages/fileimport-service/ifc-dotnet/Program.cs b/packages/fileimport-service/ifc-dotnet/Program.cs index 2115099c2a..891162a839 100644 --- a/packages/fileimport-service/ifc-dotnet/Program.cs +++ b/packages/fileimport-service/ifc-dotnet/Program.cs @@ -1,7 +1,61 @@ using System.CommandLine; +using System.Diagnostics; using System.Text.Json; +using Ara3D.Utils; +using Microsoft.Extensions.DependencyInjection; +using Speckle.Converter; +using Speckle.Importers.Ifc; +using Speckle.Importers.Ifc.Ara3D.IfcParser; +using Speckle.Importers.Ifc.Converters; +using Speckle.Importers.Ifc.Types; using Speckle.Sdk.Common; -using Speckle.WebIfc.Importer; +using Speckle.Sdk.Serialisation.V2.Send; +using Speckle.Sdk.SQLite; + +async Task RunTest() +{ + var serviceProvider = Import.GetServiceProvider(); + + var filePath = new FilePath( + "ifcs/231110ADT-FZK-Haus-2005-2006.ifc" + ); + + var ifcFactory = serviceProvider.GetRequiredService(); + var stopwatch = Stopwatch.StartNew(); + + Console.WriteLine($"Opening with WebIFC: {filePath}"); + var model = ifcFactory.Open(filePath); + var ms = stopwatch.ElapsedMilliseconds; + Console.WriteLine($"Opened with WebIFC: {ms} ms"); + + var graph = IfcGraph.Load(new FilePath(filePath)); + var ms2 = stopwatch.ElapsedMilliseconds; + Console.WriteLine($"Loaded with StepParser: {ms2 - ms} ms"); + + var converter = serviceProvider.GetRequiredService(); + var b = converter.Convert(model, graph); + ms = ms2; + ms2 = stopwatch.ElapsedMilliseconds; + Console.WriteLine($"Converted to Speckle Bases: {ms2 - ms} ms"); + + var cache = $"{Guid.NewGuid()}.db"; + using var sqlite = new SqLiteJsonCacheManager($"Data Source={cache};", 2); + using var process2 = new SerializeProcess( + new ConsoleProgress(), + sqlite, + new DummyServerObjectManager(), + new BaseChildFinder(new BasePropertyGatherer()), + new ObjectSerializerFactory(new BasePropertyGatherer()), + new SerializeProcessOptions(SkipServer: true) + ); + Console.WriteLine($"Caching to Speckle: {cache}"); + + var (rootId, _) = await process2.Serialize(b, default).ConfigureAwait(false); + Console.WriteLine(rootId); + ms2 = stopwatch.ElapsedMilliseconds; + Console.WriteLine($"Converted to JSON: {ms2 - ms} ms"); +#pragma warning restore CA1506 +} var filePathArgument = new Argument(name: "filePath"); var outputPathArgument = new Argument("outputPath"); diff --git a/packages/fileimport-service/ifc-dotnet/ifc-converter.csproj b/packages/fileimport-service/ifc-dotnet/ifc-converter.csproj index 3183ad96ca..2745959e6e 100644 --- a/packages/fileimport-service/ifc-dotnet/ifc-converter.csproj +++ b/packages/fileimport-service/ifc-dotnet/ifc-converter.csproj @@ -10,7 +10,7 @@ - +