Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tekla): adds component unpacker to tekla connector #335

Merged
merged 6 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Connectors/Tekla/Speckle.Connector.Tekla2024/GlobalUsing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
global using TG = Tekla.Structures.Geometry3d;
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 @@ -15,6 +15,7 @@
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Connectors.DUI.WebView;
using Speckle.Converter.Tekla2024;
using Speckle.Converter.Tekla2024.Helpers;

Check failure on line 18 in Connectors/Tekla/Speckle.Connector.Tekla2024/ServiceRegistration.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Helpers' does not exist in the namespace 'Speckle.Converter.Tekla2024' (are you missing an assembly reference?)

Check failure on line 18 in Connectors/Tekla/Speckle.Connector.Tekla2024/ServiceRegistration.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Helpers' does not exist in the namespace 'Speckle.Converter.Tekla2024' (are you missing an assembly reference?)
using Speckle.Converters.Common;
using Speckle.Sdk;
using Speckle.Sdk.Models.GraphTraversal;
Expand Down Expand Up @@ -66,6 +67,7 @@
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
Loading