From 4215f904561305b7f0e6dfa6bdb8339b9ae42574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinhagen?= Date: Mon, 18 Nov 2024 16:06:13 +0000 Subject: [PATCH] CNX-755: Create Collections by Category (#387) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * sendCollectionManager * path Builder Removing iteration where path (currently) only contains 1 item --------- Co-authored-by: Oğuzhan Koral <45078678+oguzhankoral@users.noreply.github.com> --- .../HostApp/SendCollectionManager.cs | 41 +++++++++++++++++++ .../Operations/Send/TeklaRootObjectBuilder.cs | 7 +++- .../ServiceRegistration.cs | 1 + .../Speckle.Connectors.TeklaShared.projitems | 1 + 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Connectors/Tekla/Speckle.Connector.TeklaShared/HostApp/SendCollectionManager.cs diff --git a/Connectors/Tekla/Speckle.Connector.TeklaShared/HostApp/SendCollectionManager.cs b/Connectors/Tekla/Speckle.Connector.TeklaShared/HostApp/SendCollectionManager.cs new file mode 100644 index 000000000..6fd6e924b --- /dev/null +++ b/Connectors/Tekla/Speckle.Connector.TeklaShared/HostApp/SendCollectionManager.cs @@ -0,0 +1,41 @@ +using Speckle.Converter.Tekla2024; +using Speckle.Converters.Common; +using Speckle.Sdk.Models.Collections; + +namespace Speckle.Connector.Tekla2024.HostApp; + +public class SendCollectionManager +{ + private readonly IConverterSettingsStore _converterSettings; + private readonly Dictionary _collectionCache = new(); + + public SendCollectionManager(IConverterSettingsStore converterSettings) + { + _converterSettings = converterSettings; + } + + public Collection GetAndCreateObjectHostCollection(TSM.ModelObject teklaObject, Collection rootObject) + { + // Tekla Data Structure: rootObject > objectType > name + // Very high-level, would be good to have sub-groups in future releases + // TODO: Refine further according to section types (for beams), constituent elements (for components) etc. at later stage + var path = teklaObject.GetType().ToString().Split('.').Last(); + + // NOTE: First pass at seeing if a collection key already exists + if (_collectionCache.TryGetValue(path, out Collection? value)) + { + return value; + } + + // NOTE: As this point, we need to create a suitable collection + // This would be done using a recursive approach to see where to add collection + // However, since data structure is flat, this returns quick (Ref: Revit ;) ) + Collection childCollection = new(path); + rootObject.elements.Add(childCollection); + _collectionCache[path] = childCollection; + + rootObject = childCollection; + + return rootObject; + } +} diff --git a/Connectors/Tekla/Speckle.Connector.TeklaShared/Operations/Send/TeklaRootObjectBuilder.cs b/Connectors/Tekla/Speckle.Connector.TeklaShared/Operations/Send/TeklaRootObjectBuilder.cs index ba9603049..c58241e1d 100644 --- a/Connectors/Tekla/Speckle.Connector.TeklaShared/Operations/Send/TeklaRootObjectBuilder.cs +++ b/Connectors/Tekla/Speckle.Connector.TeklaShared/Operations/Send/TeklaRootObjectBuilder.cs @@ -20,6 +20,7 @@ public class TeklaRootObjectBuilder : IRootObjectBuilder private readonly IRootToSpeckleConverter _rootToSpeckleConverter; private readonly ISendConversionCache _sendConversionCache; private readonly IConverterSettingsStore _converterSettings; + private readonly SendCollectionManager _sendCollectionManager; private readonly ILogger _logger; private readonly ISdkActivityFactory _activityFactory; private readonly TeklaMaterialUnpacker _materialUnpacker; @@ -28,6 +29,7 @@ public TeklaRootObjectBuilder( IRootToSpeckleConverter rootToSpeckleConverter, ISendConversionCache sendConversionCache, IConverterSettingsStore converterSettings, + SendCollectionManager sendCollectionManager, ILogger logger, ISdkActivityFactory activityFactory, TeklaMaterialUnpacker materialUnpacker @@ -35,6 +37,7 @@ TeklaMaterialUnpacker materialUnpacker { _sendConversionCache = sendConversionCache; _converterSettings = converterSettings; + _sendCollectionManager = sendCollectionManager; _rootToSpeckleConverter = rootToSpeckleConverter; _logger = logger; _activityFactory = activityFactory; @@ -110,8 +113,10 @@ string projectId converted = _rootToSpeckleConverter.Convert(teklaObject); } + var collection = _sendCollectionManager.GetAndCreateObjectHostCollection(teklaObject, collectionHost); + // Add to host collection - collectionHost.elements.Add(converted); + collection.elements.Add(converted); return new(Status.SUCCESS, applicationId, sourceType, converted); } diff --git a/Connectors/Tekla/Speckle.Connector.TeklaShared/ServiceRegistration.cs b/Connectors/Tekla/Speckle.Connector.TeklaShared/ServiceRegistration.cs index 9c3621c7e..71da6f5c4 100644 --- a/Connectors/Tekla/Speckle.Connector.TeklaShared/ServiceRegistration.cs +++ b/Connectors/Tekla/Speckle.Connector.TeklaShared/ServiceRegistration.cs @@ -56,6 +56,7 @@ public static IServiceCollection AddTekla(this IServiceCollection services) services.AddScoped(); services.AddSingleton(); services.AddSingleton(DefaultTraversal.CreateTraversalFunc()); + services.AddScoped(); services.AddScoped, TeklaRootObjectBuilder>(); services.AddScoped>(); diff --git a/Connectors/Tekla/Speckle.Connector.TeklaShared/Speckle.Connectors.TeklaShared.projitems b/Connectors/Tekla/Speckle.Connector.TeklaShared/Speckle.Connectors.TeklaShared.projitems index a86ba6eb7..e9782ec4d 100644 --- a/Connectors/Tekla/Speckle.Connector.TeklaShared/Speckle.Connectors.TeklaShared.projitems +++ b/Connectors/Tekla/Speckle.Connector.TeklaShared/Speckle.Connectors.TeklaShared.projitems @@ -21,6 +21,7 @@ +