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 @@ +