Skip to content

Commit

Permalink
CNX-755: Create Collections by Category (#387)
Browse files Browse the repository at this point in the history
* sendCollectionManager

* path Builder

Removing iteration where path (currently) only contains 1 item

---------

Co-authored-by: Oğuzhan Koral <[email protected]>
  • Loading branch information
bjoernsteinhagen and oguzhankoral authored Nov 18, 2024
1 parent c8ac385 commit 4215f90
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<TeklaConversionSettings> _converterSettings;
private readonly Dictionary<string, Collection> _collectionCache = new();

public SendCollectionManager(IConverterSettingsStore<TeklaConversionSettings> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class TeklaRootObjectBuilder : IRootObjectBuilder<TSM.ModelObject>
private readonly IRootToSpeckleConverter _rootToSpeckleConverter;
private readonly ISendConversionCache _sendConversionCache;
private readonly IConverterSettingsStore<TeklaConversionSettings> _converterSettings;
private readonly SendCollectionManager _sendCollectionManager;
private readonly ILogger<TeklaRootObjectBuilder> _logger;
private readonly ISdkActivityFactory _activityFactory;
private readonly TeklaMaterialUnpacker _materialUnpacker;
Expand All @@ -28,13 +29,15 @@ public TeklaRootObjectBuilder(
IRootToSpeckleConverter rootToSpeckleConverter,
ISendConversionCache sendConversionCache,
IConverterSettingsStore<TeklaConversionSettings> converterSettings,
SendCollectionManager sendCollectionManager,
ILogger<TeklaRootObjectBuilder> logger,
ISdkActivityFactory activityFactory,
TeklaMaterialUnpacker materialUnpacker
)
{
_sendConversionCache = sendConversionCache;
_converterSettings = converterSettings;
_sendCollectionManager = sendCollectionManager;
_rootToSpeckleConverter = rootToSpeckleConverter;
_logger = logger;
_activityFactory = activityFactory;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static IServiceCollection AddTekla(this IServiceCollection services)
services.AddScoped<ISendFilter, TeklaSelectionFilter>();
services.AddSingleton<ISendConversionCache, SendConversionCache>();
services.AddSingleton(DefaultTraversal.CreateTraversalFunc());
services.AddScoped<SendCollectionManager>();
services.AddScoped<IRootObjectBuilder<ModelObject>, TeklaRootObjectBuilder>();
services.AddScoped<SendOperation<ModelObject>>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Extensions\SpeckleApplicationIdExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Filters\TeklaSelectionFilter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GlobalUsing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\SendCollectionManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\TeklaDocumentModelStore.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\TeklaIdleManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\TeklaMaterialUnpacker.cs" />
Expand Down

0 comments on commit 4215f90

Please sign in to comment.