Skip to content

Commit

Permalink
feat(tekla): adds component unpacker to tekla connector (#335)
Browse files Browse the repository at this point in the history
* adds component unpacker to tekla connector

* removes model object converter

* Update ComponentUnpacker.cs

* Update ComponentUnpacker.cs
  • Loading branch information
clairekuang authored Oct 30, 2024
1 parent 9e68b55 commit 0debe8f
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using TSM = Tekla.Structures.Model;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Speckle.Converter.Tekla2024.Extensions;
using Speckle.Sdk.Models.Proxies;

namespace Speckle.Connector.Tekla2024.HostApp;

public class ComponentUnpacker
{
// POC: should add ILogger here in the case that component unpacker fails to unpack a component

/// <summary>
/// Stores processed Base Components as group proxies. These include Components and Connections.
/// Expects to be scoped per send operation. Should be added to the root collection.
/// </summary>
public Dictionary<string, GroupProxy> ComponentProxiesCache { get; } = new();

public ComponentUnpacker() { }

public IEnumerable<TSM.ModelObject> UnpackComponents(IReadOnlyList<TSM.ModelObject> modelObjects)
{
foreach (TSM.ModelObject modelObject in modelObjects)
{
if (modelObject is TSM.BaseComponent component)
{
// create a group proxy for this component
string appId = component.GetSpeckleApplicationId();
List<string> childIds = new();

foreach (TSM.ModelObject child in component.GetChildren())
{
childIds.Add(child.GetSpeckleApplicationId());
yield return child;
}

GroupProxy componentProxy =
new()
{
name = component.Name,
objects = childIds,
applicationId = appId
};

componentProxy["number"] = component.Number;

if (!ComponentProxiesCache.ContainsKey(appId))
{
ComponentProxiesCache.Add(appId, componentProxy);
}
}
else
{
yield return modelObject;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using Speckle.Connector.Tekla2024.HostApp;
using Speckle.Connectors.Common.Builders;
using Speckle.Connectors.Common.Caching;
using Speckle.Connectors.Common.Conversion;
Expand All @@ -21,20 +22,23 @@ public class TeklaRootObjectBuilder : IRootObjectBuilder<ModelObject>
private readonly IConverterSettingsStore<TeklaConversionSettings> _converterSettings;
private readonly ILogger<TeklaRootObjectBuilder> _logger;
private readonly ISdkActivityFactory _activityFactory;
private readonly ComponentUnpacker _componentUnpacker;

public TeklaRootObjectBuilder(
IRootToSpeckleConverter rootToSpeckleConverter,
ISendConversionCache sendConversionCache,
IConverterSettingsStore<TeklaConversionSettings> converterSettings,
ILogger<TeklaRootObjectBuilder> logger,
ISdkActivityFactory activityFactory
ISdkActivityFactory activityFactory,
ComponentUnpacker componentUnpacker
)
{
_sendConversionCache = sendConversionCache;
_converterSettings = converterSettings;
_rootToSpeckleConverter = rootToSpeckleConverter;
_logger = logger;
_activityFactory = activityFactory;
_componentUnpacker = componentUnpacker;
}

public async Task<RootObjectBuilderResult> Build(
Expand All @@ -52,12 +56,16 @@ public async Task<RootObjectBuilderResult> Build(
Collection rootObjectCollection = new() { name = modelName };
rootObjectCollection["units"] = _converterSettings.Current.SpeckleUnits;

// Step 0: unpack all component model objects
List<TSM.ModelObject> unpackedTeklaObjects = _componentUnpacker.UnpackComponents(teklaObjects).ToList();
rootObjectCollection["componentProxies"] = _componentUnpacker.ComponentProxiesCache.Values;

List<SendConversionResult> results = new(teklaObjects.Count);
int count = 0;

using (var _ = _activityFactory.Start("Convert all"))
{
foreach (ModelObject teklaObject in teklaObjects)
foreach (ModelObject teklaObject in unpackedTeklaObjects)
{
using var _2 = _activityFactory.Start("Convert");
cancellationToken.ThrowIfCancellationRequested();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static IServiceCollection AddTekla(this IServiceCollection services)
IConverterSettingsStore<TeklaConversionSettings>,
ConverterSettingsStore<TeklaConversionSettings>
>();
services.AddScoped<ComponentUnpacker>();

services.AddMatchingInterfacesAsTransient(converterAssembly);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Speckle.Converter.Tekla2024.Extensions;

public static class SpeckleApplicationIdExtensions
{
public static string GetSpeckleApplicationId(this TSM.ModelObject modelObject) =>
modelObject.Identifier.GUID.ToString();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using Speckle.Converter.Tekla2024.Extensions;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Converters.Common.Registration;
Expand Down Expand Up @@ -38,7 +39,7 @@ public Base Convert(object target)
Base result = objectConverter.Convert(target);

// add tekla specific identifiers
result.applicationId = modelObject.Identifier.GUID.ToString();
result.applicationId = modelObject.GetSpeckleApplicationId();
//TODO: attach properties

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ public IEnumerable<Base> GetDisplayValue(TSM.ModelObject modelObject)
// both beam and contour plate are child classes of part
// its simpler to use part for common methods
case TSM.Part part:
var solid = part.GetSolid();
if (solid != null)
if (part.GetSolid() is TSM.Solid partSolid)
{
var mesh = _meshConverter.Convert(solid);
yield return mesh;
yield return _meshConverter.Convert(partSolid);
}
break;

case TSM.BoltGroup boltGroup:
if (boltGroup.GetSolid() is TSM.Solid boltSolid)
{
yield return _meshConverter.Convert(boltSolid);
}
break;

Expand Down

0 comments on commit 0debe8f

Please sign in to comment.