Skip to content

Commit

Permalink
adds a setting to send rebars as line or solid (#367)
Browse files Browse the repository at this point in the history
Co-authored-by: Oğuzhan Koral <[email protected]>
  • Loading branch information
dogukankaratas and oguzhankoral authored Nov 7, 2024
1 parent 0625537 commit cac8e1b
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Speckle.Connector.Tekla2024.Operations.Send.Settings;
using Speckle.Connectors.Common.Caching;
using Speckle.Connectors.Common.Cancellation;
using Speckle.Connectors.Common.Operations;
Expand Down Expand Up @@ -42,6 +43,7 @@ public sealed class TeklaSendBinding : ISendBinding, IDisposable
private readonly ISdkActivityFactory _activityFactory;
private readonly Model _model;
private readonly Events _events;
private readonly ToSpeckleSettingsManager _toSpeckleSettingsManager;

private ConcurrentDictionary<string, byte> ChangedObjectIds { get; set; } = new();

Expand All @@ -57,7 +59,8 @@ public TeklaSendBinding(
ILogger<TeklaSendBinding> logger,
ITeklaConversionSettingsFactory teklaConversionSettingsFactory,
ISpeckleApplication speckleApplication,
ISdkActivityFactory activityFactory
ISdkActivityFactory activityFactory,
ToSpeckleSettingsManager toSpeckleSettingsManager
)
{
_store = store;
Expand All @@ -73,6 +76,7 @@ ISdkActivityFactory activityFactory
Parent = parent;
Commands = new SendBindingUICommands(parent);
_activityFactory = activityFactory;
_toSpeckleSettingsManager = toSpeckleSettingsManager;

_model = new Model();
_events = new Events();
Expand Down Expand Up @@ -103,22 +107,24 @@ private void ModelHandler_OnChange(List<ChangeData> changes)

public List<ISendFilter> GetSendFilters() => _sendFilters;

public List<ICardSetting> GetSendSettings() => [];
public List<ICardSetting> GetSendSettings() => [new SendRebarsAsSolidSetting(false)];

public async Task Send(string modelCardId)
{
using var activity = _activityFactory.Start();
using var scope = _serviceProvider.CreateScope();
scope
.ServiceProvider.GetRequiredService<IConverterSettingsStore<TeklaConversionSettings>>()
.Initialize(_teklaConversionSettingsFactory.Create(_model));

try
{
if (_store.GetModelById(modelCardId) is not SenderModelCard modelCard)
{
throw new InvalidOperationException("No publish model card was found.");
}
using var scope = _serviceProvider.CreateScope();
scope
.ServiceProvider.GetRequiredService<IConverterSettingsStore<TeklaConversionSettings>>()
.Initialize(
_teklaConversionSettingsFactory.Create(_model, _toSpeckleSettingsManager.GetSendRebarsAsSolid(modelCard))
);

CancellationToken cancellationToken = _cancellationManager.InitCancellationTokenSource(modelCardId);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Speckle.Connectors.DUI.Settings;

namespace Speckle.Connector.Tekla2024.Operations.Send.Settings;

public class SendRebarsAsSolidSetting(bool value) : ICardSetting
{
public string? Id { get; set; } = "sendRebarsAsSolid";
public string? Title { get; set; } = "Send Rebars As Solid";
public string? Type { get; set; } = "boolean";
public object? Value { get; set; } = value;
public List<string>? Enum { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Speckle.Connectors.Common.Caching;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.InterfaceGenerator;
using Speckle.Sdk.Common;

namespace Speckle.Connector.Tekla2024.Operations.Send.Settings;

[GenerateAutoInterface]
public class ToSpeckleSettingsManager : IToSpeckleSettingsManager
{
private readonly ISendConversionCache _sendConversionCache;
private readonly Dictionary<string, bool?> _sendRebarsAsSolidCache = new();

public ToSpeckleSettingsManager(ISendConversionCache sendConversionCache)
{
_sendConversionCache = sendConversionCache;
}

public bool GetSendRebarsAsSolid(SenderModelCard modelCard)
{
var value = modelCard.Settings?.First(s => s.Id == "sendRebarsAsSolid").Value as bool?;
var returnValue = value != null && value.NotNull();
if (_sendRebarsAsSolidCache.TryGetValue(modelCard.ModelCardId.NotNull(), out bool? previousValue))
{
if (previousValue != returnValue)
{
EvictCacheForModelCard(modelCard);
}
}
_sendRebarsAsSolidCache[modelCard.ModelCardId] = returnValue;
return returnValue;
}

private void EvictCacheForModelCard(SenderModelCard modelCard)
{
var objectIds = modelCard.SendFilter != null ? modelCard.SendFilter.NotNull().GetObjectIds() : [];
_sendConversionCache.EvictObjects(objectIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Speckle.Connector.Tekla2024.Filters;
using Speckle.Connector.Tekla2024.HostApp;
using Speckle.Connector.Tekla2024.Operations.Send;
using Speckle.Connector.Tekla2024.Operations.Send.Settings;
using Speckle.Connectors.Common;
using Speckle.Connectors.Common.Builders;
using Speckle.Connectors.Common.Caching;
Expand Down Expand Up @@ -58,6 +59,8 @@ public static IServiceCollection AddTekla(this IServiceCollection services)
services.AddScoped<IRootObjectBuilder<ModelObject>, TeklaRootObjectBuilder>();
services.AddScoped<SendOperation<ModelObject>>();

services.AddSingleton<ToSpeckleSettingsManager>();

services.AddTransient<CancellationManager>();
services.AddSingleton<IOperationProgressManager, OperationProgressManager>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Speckle.Converter.Tekla2024;

public record TeklaConversionSettings(Model Document, string SpeckleUnits);
public record TeklaConversionSettings(Model Document, bool SendRebarsAsSolid, string SpeckleUnits);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ IConverterSettingsStore<TeklaConversionSettings> settingsStore
public TeklaConversionSettings Current => settingsStore.Current;

// only handles automatic rn
public TeklaConversionSettings Create(Model document) =>
new(document, unitsConverter.ConvertOrThrow(TSD.Units.Automatic));
public TeklaConversionSettings Create(Model document, bool sendRebarsAsSolid) =>
new(document, sendRebarsAsSolid, unitsConverter.ConvertOrThrow(TSD.Units.Automatic));
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Sdk.Common.Exceptions;
using Speckle.Sdk.Models;

namespace Speckle.Converter.Tekla2024.ToSpeckle.Helpers;
Expand Down Expand Up @@ -49,29 +50,43 @@ public IEnumerable<Base> GetDisplayValue(TSM.ModelObject modelObject)
}
break;

// this section visualizes the rebars as lines
case TSM.Reinforcement reinforcement:
var rebarGeometries = reinforcement.GetRebarComplexGeometries(
withHooks: true,
withoutClashes: true,
lengthAdjustments: true,
TSM.Reinforcement.RebarGeometrySimplificationTypeEnum.RATIONALIZED
);

foreach (TSM.RebarComplexGeometry barGeometry in rebarGeometries)
if (_settingsStore.Current.SendRebarsAsSolid)
{
foreach (var leg in barGeometry.Legs)
if (reinforcement.GetSolid() is TSM.Solid reinforcementSolid)
{
if (leg.Curve is TG.LineSegment legLine)
{
yield return _lineConverter.Convert(legLine);
}
else if (leg.Curve is TG.Arc legArc)
yield return _meshConverter.Convert(reinforcementSolid);
}
else
{
throw new ConversionException("The type has no solid.");
}
}
else
{
var rebarGeometries = reinforcement.GetRebarComplexGeometries(
withHooks: true,
withoutClashes: true,
lengthAdjustments: true,
TSM.Reinforcement.RebarGeometrySimplificationTypeEnum.RATIONALIZED
);

foreach (TSM.RebarComplexGeometry barGeometry in rebarGeometries)
{
foreach (var leg in barGeometry.Legs)
{
yield return _arcConverter.Convert(legArc);
if (leg.Curve is TG.LineSegment legLine)
{
yield return _lineConverter.Convert(legLine);
}
else if (leg.Curve is TG.Arc legArc)
{
yield return _arcConverter.Convert(legArc);
}
}
}
}

break;

case TSM.Grid grid:
Expand All @@ -82,15 +97,6 @@ public IEnumerable<Base> GetDisplayValue(TSM.ModelObject modelObject)

break;

// use this section to visualize rebars as solid
// case TSM.Reinforcement reinforcement:
// if (reinforcement.GetSolid() is TSM.Solid reinforcementSolid)
// {
// yield return _meshConverter.Convert(reinforcementSolid);
// }
// break;


default:
yield break;
}
Expand Down

0 comments on commit cac8e1b

Please sign in to comment.