Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Jan 14, 2025
1 parent 58e3442 commit 9e44f9f
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 87 deletions.
31 changes: 14 additions & 17 deletions Connectors/Ifc/Speckle.Connectors.Ifc/Ara3D.IfcParser/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,27 @@ namespace Speckle.Connectors.Ifc.Ara3D.IfcParser;

public static class IfcExtensions
{
public static void Add<TKey, TValue>(
this IDictionary<TKey, List<TValue>> self,
TKey key,
TValue value
)
public static void Add<TKey, TValue>(this IDictionary<TKey, List<TValue>> self, TKey key, TValue value)
{
if (!self.ContainsKey(key))
self[key] = new List<TValue>();
self[key].Add(value);
}

public static uint AsId(this StepValue value) =>
value is StepUnassigned ? 0u : ((StepId)value).Id;
public static uint AsId(this StepValue value) => value is StepUnassigned ? 0u : ((StepId)value).Id;

public static string AsString(this StepValue value) =>
value is StepString ss ? ss.AsString()
: value is StepNumber sn ? sn.Value.ToString()
: value is StepId si ? si.Id.ToString()
: value is StepSymbol ssm ? ssm.Name.ToString()
: "";

public static double AsNumber(this StepValue value) =>
value is StepUnassigned ? 0 : ((StepNumber)value).Value;
value is StepString ss
? ss.AsString()
: value is StepNumber sn
? sn.Value.ToString()
: value is StepId si
? si.Id.ToString()
: value is StepSymbol ssm
? ssm.Name.ToString()
: "";

public static double AsNumber(this StepValue value) => value is StepUnassigned ? 0 : ((StepNumber)value).Value;

public static List<StepValue> AsList(this StepValue value) =>
value is StepUnassigned ? new List<StepValue>() : ((StepList)value).Values;
Expand All @@ -38,8 +36,7 @@ public static List<uint> AsIdList(this StepValue value) =>

// Uses Latin1 encoding (aka ISO-8859-1)
// Extended characters converted using an IFC specific system
public static string AsString(this ByteSpan span) =>
Encoding.Latin1.GetString(span.ToSpan()).IfcToUnicode();
public static string AsString(this ByteSpan span) => Encoding.Latin1.GetString(span.ToSpan()).IfcToUnicode();

// https://technical.buildingsmart.org/resources/ifcimplementationguidance/string-encoding/
public static string IfcToUnicode(this string input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public override bool Equals(object? obj)

public override string ToString() => $"{Type}#{Id}";

public bool IsIfcRoot =>
Count >= 4 && this[0] is StepString && (this[1] is StepId) || (this[1] is StepUnassigned);
public bool IsIfcRoot => Count >= 4 && this[0] is StepString && (this[1] is StepId) || (this[1] is StepUnassigned);

// Modern IFC files conform to this, but older ones have been observed to have different length IDs.
// Leaving as a comment for now.
Expand Down
29 changes: 8 additions & 21 deletions Connectors/Ifc/Speckle.Connectors.Ifc/Ara3D.IfcParser/IfcGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ public static IfcGraph Load(FilePath fp, ILogger? logger = null) =>

public Dictionary<uint, IfcNode> Nodes { get; } = new Dictionary<uint, IfcNode>();
public List<IfcRelation> Relations { get; } = new List<IfcRelation>();
public Dictionary<uint, List<IfcRelation>> RelationsByNode { get; } =
new Dictionary<uint, List<IfcRelation>>();
public Dictionary<uint, List<IfcPropSet>> PropertySetsByNode { get; } =
new Dictionary<uint, List<IfcPropSet>>();
public Dictionary<uint, List<IfcRelation>> RelationsByNode { get; } = new Dictionary<uint, List<IfcRelation>>();
public Dictionary<uint, List<IfcPropSet>> PropertySetsByNode { get; } = new Dictionary<uint, List<IfcPropSet>>();

public IReadOnlyList<uint> RootIds { get; }

Expand Down Expand Up @@ -162,11 +160,7 @@ public IfcGraph(StepDocument d, ILogger? logger = null)
}

logger?.Log("Retrieving the roots of all of the spatial relationship");
RootIds = GetSpatialRelations()
.Where(r => r.From != null)
.Select(r => r.From.Id)
.Distinct()
.ToList();
RootIds = GetSpatialRelations().Where(r => r.From != null).Select(r => r.From.Id).Distinct().ToList();

logger?.Log("Creating lookup of property sets");

Expand Down Expand Up @@ -194,21 +188,16 @@ public IfcNode GetOrCreateNode(StepInstance lineData, int arg)
}

public IfcNode GetOrCreateNode(StepValue o) =>
GetOrCreateNode(
o is StepId id ? id.Id : throw new SpeckleIfcException($"Expected a StepId value, not {o}")
);
GetOrCreateNode(o is StepId id ? id.Id : throw new SpeckleIfcException($"Expected a StepId value, not {o}"));

public IfcNode GetOrCreateNode(uint id)
{
var r = Nodes.TryGetValue(id, out var node)
? node
: AddNode(new IfcNode(this, Document.GetInstanceWithData(id)));
var r = Nodes.TryGetValue(id, out var node) ? node : AddNode(new IfcNode(this, Document.GetInstanceWithData(id)));
Debug.Assert(r.Id == id);
return r;
}

public List<IfcNode> GetOrCreateNodes(List<StepValue> list) =>
list.Select(GetOrCreateNode).ToList();
public List<IfcNode> GetOrCreateNodes(List<StepValue> list) => list.Select(GetOrCreateNode).ToList();

public List<IfcNode> GetOrCreateNodes(StepInstance line, int arg)
{
Expand All @@ -234,11 +223,9 @@ public IfcNode GetNode(uint id)

public IEnumerable<IfcProp> GetProps() => GetNodes().OfType<IfcProp>();

public IEnumerable<IfcRelationSpatial> GetSpatialRelations() =>
Relations.OfType<IfcRelationSpatial>();
public IEnumerable<IfcRelationSpatial> GetSpatialRelations() => Relations.OfType<IfcRelationSpatial>();

public IEnumerable<IfcRelationAggregate> GetAggregateRelations() =>
Relations.OfType<IfcRelationAggregate>();
public IEnumerable<IfcRelationAggregate> GetAggregateRelations() => Relations.OfType<IfcRelationAggregate>();

public IReadOnlyList<IfcRelation> GetRelationsFrom(uint id) =>
RelationsByNode.TryGetValue(id, out var list) ? list : Array.Empty<IfcRelation>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ public static class AlignedMemoryReader
{
public static unsafe AlignedMemory ReadAllBytes(string path, int bufferSize = 1024 * 1024)
{
using var fs = new FileStream(
path,
FileMode.Open,
FileAccess.Read,
FileShare.Read,
bufferSize,
false
);
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, false);
var fileLength = fs.Length;
if (fileLength > int.MaxValue)
throw new IOException("File too big: > 2GB");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ public StepDocument(FilePath filePath, ILogger? logger = null)
var currentLine = 1;
for (var i = 0; i < Data.NumVectors; i++)
{
StepLineParser.ComputeOffsets(
((Vector256<byte>*)Data.BytePtr)[i],
ref currentLine,
LineOffsets
);
StepLineParser.ComputeOffsets(((Vector256<byte>*)Data.BytePtr)[i], ref currentLine, LineOffsets);
}

logger.Log($"Found {LineOffsets.Count} lines");
Expand All @@ -83,11 +79,9 @@ public StepDocument(FilePath filePath, ILogger? logger = null)

public void Dispose() => Data.Dispose();

public StepInstance GetInstanceWithData(uint id) =>
GetInstanceWithDataFromIndex(InstanceIdToIndex[id]);
public StepInstance GetInstanceWithData(uint id) => GetInstanceWithDataFromIndex(InstanceIdToIndex[id]);

public StepInstance GetInstanceWithDataFromIndex(int index) =>
GetInstanceWithData(RawInstances[index]);
public StepInstance GetInstanceWithDataFromIndex(int index) => GetInstanceWithData(RawInstances[index]);

public StepInstance GetInstanceWithData(StepRawInstance inst)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ public static unsafe StepToken ParseToken(byte* begin, byte* end)
public static unsafe bool EatWSpace(ref StepToken cur, byte* end)
{
while (
cur.Type == StepTokenType.Comment
|| cur.Type == StepTokenType.Whitespace
|| cur.Type == StepTokenType.LineBreak
cur.Type == StepTokenType.Comment || cur.Type == StepTokenType.Whitespace || cur.Type == StepTokenType.LineBreak
)
{
if (!ParseNextToken(ref cur, end))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ public unsafe Mesh Convert(IfcMesh mesh)
}

var color = mesh.GetColor();
List<int> colors =
[
(int)(color->A * 255),
(int)(color->R * 255),
(int)(color->G * 255),
(int)(color->B * 255),
];
List<int> colors = [(int)(color->A * 255), (int)(color->R * 255), (int)(color->G * 255), (int)(color->B * 255),];
return new Mesh()
{
colors = colors,
Expand Down
22 changes: 7 additions & 15 deletions Connectors/Ifc/Speckle.Connectors.Ifc/Import.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,7 @@ public static async Task<string> Ifc(
)
{
var serviceProvider = GetServiceProvider();
return await Ifc(
serviceProvider,
url,
filePath,
streamId,
modelId,
commitMessage,
token,
progress
);
return await Ifc(serviceProvider, url, filePath, streamId, modelId, commitMessage, token, progress);
}

public static ServiceProvider GetServiceProvider()
Expand Down Expand Up @@ -93,11 +84,12 @@ public static async Task<string> Ifc(
new SerializeProcessOptions(true, true, true, false)
);
var (rootId, _) = await process.Serialize(b, default).ConfigureAwait(false);
Account account = new()
{
token = token,
serverInfo = new ServerInfo { url = baseUri.ToString() },
};
Account account =
new()
{
token = token,
serverInfo = new ServerInfo { url = baseUri.ToString() },
};
ms = ms2;
ms2 = stopwatch.ElapsedMilliseconds;
Console.WriteLine($"Uploaded to Speckle: {ms2 - ms} ms");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Speckle.Connectors.Ifc.Types;
using Speckle.Sdk;

namespace Speckle.Connectors.Ifc;

public static class ServiceRegistration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Speckle.Importer.Tester;
public class DummySendCacheManager(Dictionary<string, string> objects) : ISqLiteJsonCacheManager
{
public void Dispose() { }

public IReadOnlyCollection<(string, string)> GetAllObjects() => throw new NotImplementedException();

public void DeleteObject(string id) => throw new NotImplementedException();
Expand Down
11 changes: 6 additions & 5 deletions Connectors/Ifc/Speckle.Importer.Tester/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
var serviceProvider = Import.GetServiceProvider();
DotMemory.Init();
var filePath = new FilePath(
//"C:\\Users\\adam\\Git\\speckle-server\\packages\\fileimport-service\\ifc-dotnet\\ifcs\\20210221PRIMARK.ifc"
//"C:\\Users\\adam\\Git\\speckle-server\\packages\\fileimport-service\\ifc-dotnet\\ifcs\\231110ADT-FZK-Haus-2005-2006.ifc"
//"C:\\Users\\adam\\Downloads\\T03PV06IMPMI01C.ifc"
"C:\\Users\\adam\\Downloads\\20231128_HW_Bouwkosten.ifc"
//"C:\\Users\\adam\\Git\\speckle-server\\packages\\fileimport-service\\ifc-dotnet\\ifcs\\20210221PRIMARK.ifc"
//"C:\\Users\\adam\\Git\\speckle-server\\packages\\fileimport-service\\ifc-dotnet\\ifcs\\231110ADT-FZK-Haus-2005-2006.ifc"
//"C:\\Users\\adam\\Downloads\\T03PV06IMPMI01C.ifc"
"C:\\Users\\adam\\Downloads\\20231128_HW_Bouwkosten.ifc"
);

var ifcFactory = serviceProvider.GetRequiredService<IIfcFactory>();
Expand Down Expand Up @@ -45,9 +45,10 @@
new DummyServerObjectManager(),
new BaseChildFinder(new BasePropertyGatherer()),
new ObjectSerializerFactory(new BasePropertyGatherer()),
new SerializeProcessOptions(SkipServer:true)
new SerializeProcessOptions(SkipServer: true)
);
Console.WriteLine($"Caching to Speckle: {cache}");

/*var config = new DotMemory.Config();
config.OpenDotMemory();
config.SaveToDir("C:\\Users\\adam\\dotTraceSnapshots");
Expand Down

0 comments on commit 9e44f9f

Please sign in to comment.