Skip to content

Commit

Permalink
Merge pull request #4 from specklesystems/alan/misc-importer-fixes
Browse files Browse the repository at this point in the history
Detachment and SDK updates for importer fixes
  • Loading branch information
adamhathcock authored Dec 11, 2024
2 parents 4c5ef03 + 391f493 commit 793dcf8
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 46 deletions.
6 changes: 3 additions & 3 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<PackageVersion Include="Glob" Version="1.1.9" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageVersion Include="SimpleExec" Version="12.0.0" />
<PackageVersion Include="Speckle.Objects" Version="3.1.0-dev.200" />
<PackageVersion Include="Speckle.Sdk" Version="3.1.0-dev.200" />
<PackageVersion Include="Speckle.Sdk.Dependencies" Version="3.1.0-dev.200" />
<PackageVersion Include="Speckle.Objects" Version="3.1.0-dev.215" />
<PackageVersion Include="Speckle.Sdk" Version="3.1.0-dev.215" />
<PackageVersion Include="Speckle.Sdk.Dependencies" Version="3.1.0-dev.215" />
<PackageVersion Include="Speckle.WebIfc" Version="0.0.64-speckle1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
Expand Down
24 changes: 24 additions & 0 deletions src/Speckle.Importer.Tester/DummySendCacheManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Speckle.Sdk.SQLite;

namespace Speckle.Importer.Tester;

public class DummySendCacheManager(Dictionary<string, string> objects) : ISqLiteJsonCacheManager
{
public IEnumerable<string> GetAllObjects() => throw new NotImplementedException();

public void DeleteObject(string id) => throw new NotImplementedException();

public string? GetObject(string id) => null;

public void SaveObject(string id, string json) => throw new NotImplementedException();

public bool HasObject(string objectId) => false;

public void SaveObjects(IEnumerable<(string id, string json)> items)
{
foreach (var (id, json) in items)
{
objects[id] = json;
}
}
}
43 changes: 43 additions & 0 deletions src/Speckle.Importer.Tester/DummyServerObjectManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Text;
using Speckle.Sdk.Dependencies.Serialization;
using Speckle.Sdk.Serialisation.V2;
using Speckle.Sdk.Transports;

namespace Speckle.Importer.Tester;

public class DummyServerObjectManager : IServerObjectManager
{
public IAsyncEnumerable<(string, string)> DownloadObjects(
IReadOnlyList<string> objectIds,
IProgress<ProgressArgs>? progress,
CancellationToken cancellationToken
) => throw new NotImplementedException();

public Task<string?> DownloadSingleObject(
string objectId,
IProgress<ProgressArgs>? progress,
CancellationToken cancellationToken
) => throw new NotImplementedException();

public Task<Dictionary<string, bool>> HasObjects(
IReadOnlyList<string> objectIds,
CancellationToken cancellationToken
) => throw new NotImplementedException();

public Task UploadObjects(
IReadOnlyList<BaseItem> objects,
bool compressPayloads,
IProgress<ProgressArgs>? progress,
CancellationToken cancellationToken
)
{
long totalBytes = 0;
foreach (var item in objects)
{
totalBytes += Encoding.Default.GetByteCount(item.Json);
}

progress?.Report(new(ProgressEvent.UploadBytes, totalBytes, totalBytes));
return Task.CompletedTask;
}
}
49 changes: 43 additions & 6 deletions src/Speckle.Importer.Tester/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,50 @@
using Ara3D.IfcParser;
using System.Diagnostics;
using Ara3D.IfcParser;
using Ara3D.Utils;
using Microsoft.Extensions.DependencyInjection;
using Speckle.Importer.Tester;
using Speckle.Sdk.Serialisation.V2.Send;
using Speckle.WebIfc.Importer;
using Speckle.WebIfc.Importer.Converters;
using Speckle.WebIfc.Importer.Ifc;

var serviceProvider = Import.GetServiceProvider();

var graph = IfcGraph.Load(
new FilePath(
"C:\\Users\\adam\\Git\\speckle-server\\packages\\fileimport-service\\ifc-dotnet\\ifcs\\small.ifc"
)
var filePath = new FilePath(
"C:\\Users\\adam\\Git\\speckle-server\\packages\\fileimport-service\\ifc-dotnet\\ifcs\\20210221PRIMARK.ifc"
);

Console.WriteLine(graph.Document.RawInstances.Length);
var ifcFactory = serviceProvider.GetRequiredService<IIfcFactory>();
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<IGraphConverter>();
var b = converter.Convert(model, graph);
ms = ms2;
ms2 = stopwatch.ElapsedMilliseconds;
Console.WriteLine($"Converted to Speckle Bases: {ms2 - ms} ms");
var objects = new Dictionary<string, string>();

var process2 = new SerializeProcess(
new Progress(true),
new DummySendCacheManager(objects),
new DummyServerObjectManager(),
new BaseChildFinder(new BasePropertyGatherer()),
new ObjectSerializerFactory(new BasePropertyGatherer()),
new SerializeProcessOptions(true, true, true, true)
);
Console.ReadLine();
var (rootId, _) = await process2.Serialize(b, default).ConfigureAwait(false);
Console.WriteLine(rootId);
ms2 = stopwatch.ElapsedMilliseconds;
Console.WriteLine($"Converted to JSON: {ms2 - ms} ms");

Console.ReadLine();
36 changes: 36 additions & 0 deletions src/Speckle.Importer.Tester/Progress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Speckle.Sdk.Transports;

namespace Speckle.Importer.Tester;

public class Progress(bool write) : IProgress<ProgressArgs>
{
private readonly TimeSpan DEBOUNCE = TimeSpan.FromSeconds(1);
private DateTime _lastTime = DateTime.UtcNow;

private long _totalBytes;

public void Report(ProgressArgs value)
{
if (write)
{
if (value.ProgressEvent == ProgressEvent.DownloadBytes)
{
Interlocked.Add(ref _totalBytes, value.Count);
}
var now = DateTime.UtcNow;
if (now - _lastTime >= DEBOUNCE)
{
if (value.ProgressEvent == ProgressEvent.DownloadBytes)
{
Console.WriteLine(value.ProgressEvent + " t " + _totalBytes);
}
else
{
Console.WriteLine(value.ProgressEvent + " c " + value.Count + " t " + value.Total);
}

_lastTime = now;
}
}
}
}
28 changes: 14 additions & 14 deletions src/Speckle.Importer.Tester/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@
"Ara3D.Logging": "[1.4.5, )",
"Ara3D.Utils": "[1.4.5, )",
"Microsoft.Extensions.DependencyInjection": "[8.0.1, )",
"Speckle.Objects": "[3.1.0-dev.200, )",
"Speckle.Sdk": "[3.1.0-dev.200, )",
"Speckle.Objects": "[3.1.0-dev.215, )",
"Speckle.Sdk": "[3.1.0-dev.215, )",
"Speckle.WebIfc": "[0.0.64-speckle1, )",
"System.CommandLine": "[2.0.0-beta4.22272.1, )"
}
Expand Down Expand Up @@ -253,18 +253,18 @@
},
"Speckle.Objects": {
"type": "CentralTransitive",
"requested": "[3.1.0-dev.200, )",
"resolved": "3.1.0-dev.200",
"contentHash": "n4O+XvMBTsl2gOjZmMeE1Kvo1DOxDLuBcUR7GQw8G0LPv+ce+JFSNaFnmyz/w4X32X2bHmbSImuMRr6U7K4dUQ==",
"requested": "[3.1.0-dev.215, )",
"resolved": "3.1.0-dev.215",
"contentHash": "NNiTR3dp1/4WNIv2WRHm87pr4WQztt9vVRALqULEUTcYrvb34xwnKwPwt3Ah5iXW1g3qkecXto5V7Ex+IIzeRQ==",
"dependencies": {
"Speckle.Sdk": "3.1.0-dev.200"
"Speckle.Sdk": "3.1.0-dev.215"
}
},
"Speckle.Sdk": {
"type": "CentralTransitive",
"requested": "[3.1.0-dev.200, )",
"resolved": "3.1.0-dev.200",
"contentHash": "iRdDkEFDu8taJmzMs6RK/HiUZMeESNKfovb3U2a3yO3wEElNfpqPGXJr3GKcjjPZ+LwENgNO3/aemGzx8+TXQw==",
"requested": "[3.1.0-dev.215, )",
"resolved": "3.1.0-dev.215",
"contentHash": "YMb7xdELiza88RSCUWcqmKJlrnoqjxlc1+Z1gEQSCfvFV0Ibvfjz08YAMkOWFc/ZaY9nBUZvshHEWYIskEk5cg==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand All @@ -273,14 +273,14 @@
"Microsoft.Extensions.Logging": "2.2.0",
"Speckle.DoubleNumerics": "4.0.1",
"Speckle.Newtonsoft.Json": "13.0.2",
"Speckle.Sdk.Dependencies": "3.1.0-dev.200"
"Speckle.Sdk.Dependencies": "3.1.0-dev.215"
}
},
"Speckle.Sdk.Dependencies": {
"type": "CentralTransitive",
"requested": "[3.1.0-dev.200, )",
"resolved": "3.1.0-dev.200",
"contentHash": "4ZHkKRzI6/Xa1c20NrH3+e+m5DUB+qbBSq+GJ6MShUh6SpKOC4DRdwy0qCcAWrurq7V94xU0qN+7+QzKGeWlFw=="
"requested": "[3.1.0-dev.215, )",
"resolved": "3.1.0-dev.215",
"contentHash": "cT5HRu+pRBvfKTRJIvQBgdX2X5eeTebHe7zmNz82tFT0p65RsK9K7Ap9RjvMndbEPqFtt8/sCNa5RHyfrf+IUg=="
},
"Speckle.WebIfc": {
"type": "CentralTransitive",
Expand All @@ -296,4 +296,4 @@
}
}
}
}
}
7 changes: 4 additions & 3 deletions src/Speckle.WebIfc.Importer/Converters/GraphConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Ara3D.IfcParser;
using Speckle.InterfaceGenerator;
using Speckle.Sdk.Models;
using Speckle.Sdk.Models.Collections;
using Speckle.WebIfc.Importer.Ifc;

namespace Speckle.WebIfc.Importer.Converters;
Expand All @@ -10,9 +11,9 @@ public class GraphConverter(INodeConverter nodeConverter) : IGraphConverter
{
public Base Convert(IfcModel model, IfcGraph graph)
{
var b = new Base();
var collection = new Collection();
var children = graph.GetSources().Select(x => nodeConverter.Convert(model, x)).ToList();
b["elements"] = children;
return b;
collection.elements = children;
return collection;
}
}
2 changes: 1 addition & 1 deletion src/Speckle.WebIfc.Importer/Converters/MeshConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public unsafe Mesh Convert(IfcMesh mesh)
var a = ip[i];
var b = ip[i + 1];
var c = ip[i + 2];
faces.Add(0);
faces.Add(3);
faces.Add(a);
faces.Add(b);
faces.Add(c);
Expand Down
4 changes: 2 additions & 2 deletions src/Speckle.WebIfc.Importer/Converters/NodeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public Base Convert(IfcModel model, IfcNode node)
{
var c = geometryConverter.Convert(geo);
if (c.elements.Count > 0)
b["displayValue"] = c.elements;
b["@displayValue"] = c.elements;
}

// Create the children
var children = node.GetChildren().Select(x => Convert(model, x)).ToList();
b["elements"] = children;
b["@elements"] = children;

// Add the properties
foreach (var p in node.GetPropSets())
Expand Down
7 changes: 3 additions & 4 deletions src/Speckle.WebIfc.Importer/Import.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ public static async Task<string> Ifc(
baseUri,
streamId,
token,
progress
progress,
new SerializeProcessOptions(true, true, false, true)
);
var (rootId, _) = await process
.Serialize(b, default, new SerializeProcessOptions(true, true, false))
.ConfigureAwait(false);
var (rootId, _) = await process.Serialize(b, default).ConfigureAwait(false);
Account account = new()
{
token = token,
Expand Down
4 changes: 2 additions & 2 deletions src/Speckle.WebIfc.Importer/Speckle.WebIfc.Importer.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand All @@ -7,7 +7,7 @@
<PropertyGroup Label="Nuget Package Properties">
<IsPackable>true</IsPackable>
<IncludeSymbols>true</IncludeSymbols>
<version>0.0.5</version>
<version>0.0.6</version>
</PropertyGroup>

<ItemGroup>
Expand Down
22 changes: 11 additions & 11 deletions src/Speckle.WebIfc.Importer/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@
},
"Speckle.Objects": {
"type": "Direct",
"requested": "[3.1.0-dev.200, )",
"resolved": "3.1.0-dev.200",
"contentHash": "n4O+XvMBTsl2gOjZmMeE1Kvo1DOxDLuBcUR7GQw8G0LPv+ce+JFSNaFnmyz/w4X32X2bHmbSImuMRr6U7K4dUQ==",
"requested": "[3.1.0-dev.215, )",
"resolved": "3.1.0-dev.215",
"contentHash": "NNiTR3dp1/4WNIv2WRHm87pr4WQztt9vVRALqULEUTcYrvb34xwnKwPwt3Ah5iXW1g3qkecXto5V7Ex+IIzeRQ==",
"dependencies": {
"Speckle.Sdk": "3.1.0-dev.200"
"Speckle.Sdk": "3.1.0-dev.215"
}
},
"Speckle.Sdk": {
"type": "Direct",
"requested": "[3.1.0-dev.200, )",
"resolved": "3.1.0-dev.200",
"contentHash": "iRdDkEFDu8taJmzMs6RK/HiUZMeESNKfovb3U2a3yO3wEElNfpqPGXJr3GKcjjPZ+LwENgNO3/aemGzx8+TXQw==",
"requested": "[3.1.0-dev.215, )",
"resolved": "3.1.0-dev.215",
"contentHash": "YMb7xdELiza88RSCUWcqmKJlrnoqjxlc1+Z1gEQSCfvFV0Ibvfjz08YAMkOWFc/ZaY9nBUZvshHEWYIskEk5cg==",
"dependencies": {
"GraphQL.Client": "6.0.0",
"Microsoft.CSharp": "4.7.0",
Expand All @@ -73,7 +73,7 @@
"Microsoft.Extensions.Logging": "2.2.0",
"Speckle.DoubleNumerics": "4.0.1",
"Speckle.Newtonsoft.Json": "13.0.2",
"Speckle.Sdk.Dependencies": "3.1.0-dev.200"
"Speckle.Sdk.Dependencies": "3.1.0-dev.215"
}
},
"Speckle.WebIfc": {
Expand Down Expand Up @@ -277,9 +277,9 @@
},
"Speckle.Sdk.Dependencies": {
"type": "CentralTransitive",
"requested": "[3.1.0-dev.200, )",
"resolved": "3.1.0-dev.200",
"contentHash": "4ZHkKRzI6/Xa1c20NrH3+e+m5DUB+qbBSq+GJ6MShUh6SpKOC4DRdwy0qCcAWrurq7V94xU0qN+7+QzKGeWlFw=="
"requested": "[3.1.0-dev.215, )",
"resolved": "3.1.0-dev.215",
"contentHash": "cT5HRu+pRBvfKTRJIvQBgdX2X5eeTebHe7zmNz82tFT0p65RsK9K7Ap9RjvMndbEPqFtt8/sCNa5RHyfrf+IUg=="
}
}
}
Expand Down

0 comments on commit 793dcf8

Please sign in to comment.