Skip to content

Commit

Permalink
bjorn/cnx 882 send etabsobjects with their properties (#442)
Browse files Browse the repository at this point in the history
* trying a bold refactoring

ETABSShared and CSiShared is strictly correct, but just looks horrible EtabsShared and CsiShared looks better

* refactor: improve

* property extraction foundation

- better architectural approach for property extraction depending on csi product and wrapper type
- correctly configures return type depending on the product (e.g. EtabsObject)

* refactor(props): streamline property extraction across CSi and ETABS

Reorganizes property extraction to better handle base and product-specific properties:
- Introduces PropertyExtractionResult for cleaner property management
- Separates shared CSi properties from product-specific ones
- Implements dedicated extractors for Frame, Joint, and Shell
- Standardizes property extraction patterns between CSi and ETABS
- Removes property redundancy and improves null safety

* frame data extraction 1/2

* remaining data extraction

- finished data extraction for frames
- added data extraction for joints and shells
- re-instated collections

* documentation

- added some updates to the documentation

* SpeckleApplicationIdExtensions

- Extension methods for speckle applicationIds

* IApplicationPropertiesExtractorConcretization

- Renamed GeneralPropertiesExtractor to SharedPropertiesExtractor
- Renamed EtabsClassPropertiesExtractor to ApplicationPropertiesExtractor
- Removed PropertiesExtractor file
- Enforced injection of shared properties extractor to application specific extractor
- Output of Extract() of type PropertyExtractorResult
- Application property extractor mutates dictionary

* applicationId simplification

* review comments

- directly assigning applicationId to base
- rename ApplicationPropertiesExtractor to EtabsPropertiesExtractor

---------

Co-authored-by: Claire Kuang <[email protected]>
  • Loading branch information
bjoernsteinhagen and clairekuang authored Dec 11, 2024
1 parent 0e0dd81 commit 196c503
Show file tree
Hide file tree
Showing 62 changed files with 1,316 additions and 787 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Speckle.Connectors.CSiShared.Bindings;

public class CSiSharedBasicConnectorBinding : IBasicConnectorBinding
public class CsiSharedBasicConnectorBinding : IBasicConnectorBinding
{
private readonly ISpeckleApplication _speckleApplication;
private readonly DocumentModelStore _store;
Expand All @@ -15,7 +15,7 @@ public class CSiSharedBasicConnectorBinding : IBasicConnectorBinding
public IBrowserBridge Parent { get; }
public BasicConnectorBindingCommands Commands { get; }

public CSiSharedBasicConnectorBinding(
public CsiSharedBasicConnectorBinding(
IBrowserBridge parent,
ISpeckleApplication speckleApplication,
DocumentModelStore store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

namespace Speckle.Connectors.CSiShared.Bindings;

public class CSiSharedSelectionBinding : ISelectionBinding
public class CsiSharedSelectionBinding : ISelectionBinding
{
public string Name => "selectionBinding";
public IBrowserBridge Parent { get; }
private readonly ICSiApplicationService _csiApplicationService;
private readonly ICsiApplicationService _csiApplicationService;

public CSiSharedSelectionBinding(IBrowserBridge parent, ICSiApplicationService csiApplicationService)
public CsiSharedSelectionBinding(IBrowserBridge parent, ICsiApplicationService csiApplicationService)
{
Parent = parent;
_csiApplicationService = csiApplicationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace Speckle.Connectors.CSiShared.Bindings;

public sealed class CSiSharedSendBinding : ISendBinding
public sealed class CsiSharedSendBinding : ISendBinding
{
public string Name => "sendBinding";
public SendBindingUICommands Commands { get; }
Expand All @@ -32,25 +32,25 @@ public sealed class CSiSharedSendBinding : ISendBinding
private readonly List<ISendFilter> _sendFilters;
private readonly CancellationManager _cancellationManager;
private readonly IOperationProgressManager _operationProgressManager;
private readonly ILogger<CSiSharedSendBinding> _logger;
private readonly ICSiApplicationService _csiApplicationService;
private readonly ICSiConversionSettingsFactory _csiConversionSettingsFactory;
private readonly ILogger<CsiSharedSendBinding> _logger;
private readonly ICsiApplicationService _csiApplicationService;
private readonly ICsiConversionSettingsFactory _csiConversionSettingsFactory;
private readonly ISpeckleApplication _speckleApplication;
private readonly ISdkActivityFactory _activityFactory;

public CSiSharedSendBinding(
public CsiSharedSendBinding(
DocumentModelStore store,
IAppIdleManager idleManager,
IBrowserBridge parent,
IEnumerable<ISendFilter> sendFilters,
IServiceProvider serviceProvider,
CancellationManager cancellationManager,
IOperationProgressManager operationProgressManager,
ILogger<CSiSharedSendBinding> logger,
ICSiConversionSettingsFactory csiConversionSettingsFactory,
ILogger<CsiSharedSendBinding> logger,
ICsiConversionSettingsFactory csiConversionSettingsFactory,
ISpeckleApplication speckleApplication,
ISdkActivityFactory activityFactory,
ICSiApplicationService csiApplicationService
ICsiApplicationService csiApplicationService
)
{
_store = store;
Expand Down Expand Up @@ -84,12 +84,12 @@ public async Task Send(string modelCardId)
}
using var scope = _serviceProvider.CreateScope();
scope
.ServiceProvider.GetRequiredService<IConverterSettingsStore<CSiConversionSettings>>()
.ServiceProvider.GetRequiredService<IConverterSettingsStore<CsiConversionSettings>>()
.Initialize(_csiConversionSettingsFactory.Create(_csiApplicationService.SapModel));

CancellationToken cancellationToken = _cancellationManager.InitCancellationTokenSource(modelCardId);

List<ICSiWrapper> wrappers = modelCard
List<ICsiWrapper> wrappers = modelCard
.SendFilter.NotNull()
.RefreshObjectIds()
.Select(DecodeObjectIdentifier)
Expand All @@ -101,7 +101,7 @@ public async Task Send(string modelCardId)
}

var sendResult = await scope
.ServiceProvider.GetRequiredService<SendOperation<ICSiWrapper>>()
.ServiceProvider.GetRequiredService<SendOperation<ICsiWrapper>>()
.Execute(
wrappers,
modelCard.GetSendInfo(_speckleApplication.Slug),
Expand All @@ -125,10 +125,10 @@ await Commands
}
}

private ICSiWrapper DecodeObjectIdentifier(string encodedId)
private ICsiWrapper DecodeObjectIdentifier(string encodedId)
{
var (type, name) = ObjectIdentifier.Decode(encodedId);
return CSiWrapperFactory.Create(type, name);
return CsiWrapperFactory.Create(type, name);
}

public void CancelSend(string modelCardId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Speckle.Connectors.CSiShared.Filters;

public class CSiSharedSelectionFilter : DirectSelectionSendFilter
public class CsiSharedSelectionFilter : DirectSelectionSendFilter
{
public CSiSharedSelectionFilter()
public CsiSharedSelectionFilter()
{
IsDefault = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace Speckle.Connectors.CSiShared.HostApp;
/// Prevent having to pass the "sapModel" around between classes and this ensures consistent access.
/// Name "sapModel" is misleading since it doesn't only apply to SAP2000, but this is the convention in the API, so we keep it.
/// </remarks>
public interface ICSiApplicationService
public interface ICsiApplicationService
{
cSapModel SapModel { get; }
void Initialize(cSapModel sapModel, cPluginCallback pluginCallback);
}

public class CSiApplicationService : ICSiApplicationService
public class CsiApplicationService : ICsiApplicationService
{
public cSapModel SapModel { get; private set; }
private cPluginCallback _pluginCallback;

public CSiApplicationService()
public CsiApplicationService()
{
SapModel = null!;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

namespace Speckle.Connectors.CSiShared.HostApp;

public class CSiDocumentModelStore : DocumentModelStore
public class CsiDocumentModelStore : DocumentModelStore
{
private readonly ISpeckleApplication _speckleApplication;
private readonly ILogger<CSiDocumentModelStore> _logger;
private readonly ICSiApplicationService _csiApplicationService;
private readonly ILogger<CsiDocumentModelStore> _logger;
private readonly ICsiApplicationService _csiApplicationService;
private string HostAppUserDataPath { get; set; }
private string DocumentStateFile { get; set; }
private string ModelPathHash { get; set; }

public CSiDocumentModelStore(
public CsiDocumentModelStore(
IJsonSerializer jsonSerializerSettings,
ISpeckleApplication speckleApplication,
ILogger<CSiDocumentModelStore> logger,
ICSiApplicationService csiApplicationService
ILogger<CsiDocumentModelStore> logger,
ICsiApplicationService csiApplicationService
)
: base(jsonSerializerSettings)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Speckle.Connectors.CSiShared.HostApp;

public sealed class CSiIdleManager : AppIdleManager
public sealed class CsiIdleManager : AppIdleManager
{
private readonly IIdleCallManager _idleCallManager;

public CSiIdleManager(IIdleCallManager idleCallManager)
public CsiIdleManager(IIdleCallManager idleCallManager)
: base(idleCallManager)
{
_idleCallManager = idleCallManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ namespace Speckle.Connectors.CSiShared.HostApp;
/// This class manages the collections. If the key (from the path) already exists, this collection is returned.
/// If it doesn't exist, a new collection is created and added to the rootObject.
/// </remarks>
public class CSiSendCollectionManager
public class CsiSendCollectionManager
{
protected IConverterSettingsStore<CSiConversionSettings> ConverterSettings { get; }
protected IConverterSettingsStore<CsiConversionSettings> ConverterSettings { get; }
protected Dictionary<string, Collection> CollectionCache { get; } = new();

public CSiSendCollectionManager(IConverterSettingsStore<CSiConversionSettings> converterSettings)
public CsiSendCollectionManager(IConverterSettingsStore<CsiConversionSettings> converterSettings)
{
ConverterSettings = converterSettings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@

namespace Speckle.Connectors.CSiShared.Builders;

public class CSiRootObjectBuilder : IRootObjectBuilder<ICSiWrapper>
public class CsiRootObjectBuilder : IRootObjectBuilder<ICsiWrapper>
{
private readonly IRootToSpeckleConverter _rootToSpeckleConverter;
private readonly ISendConversionCache _sendConversionCache;
private readonly IConverterSettingsStore<CSiConversionSettings> _converterSettings;
private readonly CSiSendCollectionManager _sendCollectionManager;
private readonly ILogger<CSiRootObjectBuilder> _logger;
private readonly IConverterSettingsStore<CsiConversionSettings> _converterSettings;
private readonly CsiSendCollectionManager _sendCollectionManager;
private readonly ILogger<CsiRootObjectBuilder> _logger;
private readonly ISdkActivityFactory _activityFactory;
private readonly ICSiApplicationService _csiApplicationService;
private readonly ICsiApplicationService _csiApplicationService;

public CSiRootObjectBuilder(
public CsiRootObjectBuilder(
IRootToSpeckleConverter rootToSpeckleConverter,
ISendConversionCache sendConversionCache,
IConverterSettingsStore<CSiConversionSettings> converterSettings,
CSiSendCollectionManager sendCollectionManager,
ILogger<CSiRootObjectBuilder> logger,
IConverterSettingsStore<CsiConversionSettings> converterSettings,
CsiSendCollectionManager sendCollectionManager,
ILogger<CsiRootObjectBuilder> logger,
ISdkActivityFactory activityFactory,
ICSiApplicationService csiApplicationService
ICsiApplicationService csiApplicationService
)
{
_sendConversionCache = sendConversionCache;
Expand All @@ -43,7 +43,7 @@ ICSiApplicationService csiApplicationService
}

public async Task<RootObjectBuilderResult> Build(
IReadOnlyList<ICSiWrapper> csiObjects,
IReadOnlyList<ICsiWrapper> csiObjects,
SendInfo sendInfo,
IProgress<CardProgress> onOperationProgressed,
CancellationToken cancellationToken = default
Expand All @@ -60,7 +60,7 @@ public async Task<RootObjectBuilderResult> Build(

using (var _ = _activityFactory.Start("Convert all"))
{
foreach (ICSiWrapper csiObject in csiObjects)
foreach (ICsiWrapper csiObject in csiObjects)
{
using var _2 = _activityFactory.Start("Convert");
cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -82,7 +82,7 @@ public async Task<RootObjectBuilderResult> Build(
return new RootObjectBuilderResult(rootObjectCollection, results);
}

private SendConversionResult ConvertCSiObject(ICSiWrapper csiObject, Collection typeCollection, string projectId)
private SendConversionResult ConvertCSiObject(ICsiWrapper csiObject, Collection typeCollection, string projectId)
{
string applicationId = $"{csiObject.ObjectType}{csiObject.Name}"; // TODO: NO! Use GUID
string sourceType = csiObject.ObjectName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ protected SpeckleFormBase()
protected virtual void ConfigureServices(IServiceCollection services)
{
services.Initialize(GetHostApplication(), GetVersion());
services.AddCSi();
services.AddCSiConverters();
services.AddCsi();
services.AddCsiConverters();
}

protected abstract HostApplication GetHostApplication();
Expand All @@ -48,7 +48,7 @@ public void SetSapModel(ref cSapModel sapModel, ref cPluginCallback pluginCallba
_sapModel = sapModel;
_pluginCallback = pluginCallback;

var csiService = Container.GetRequiredService<ICSiApplicationService>();
var csiService = Container.GetRequiredService<ICsiApplicationService>();
csiService.Initialize(sapModel, pluginCallback);
}

Expand Down
24 changes: 12 additions & 12 deletions Connectors/CSi/Speckle.Connectors.CSiShared/ServiceRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ namespace Speckle.Connectors.CSiShared;

public static class ServiceRegistration
{
public static IServiceCollection AddCSi(this IServiceCollection services)
public static IServiceCollection AddCsi(this IServiceCollection services)
{
services.AddSingleton<IBrowserBridge, BrowserBridge>();
services.AddSingleton<ICSiApplicationService, CSiApplicationService>();
services.AddSingleton<ICsiApplicationService, CsiApplicationService>();

services.AddConnectorUtils();
services.AddDUI<CSiDocumentModelStore>();
services.AddDUI<CsiDocumentModelStore>();
services.AddDUIView();

services.AddSingleton<DocumentModelStore, CSiDocumentModelStore>();
services.AddSingleton<DocumentModelStore, CsiDocumentModelStore>();

services.AddSingleton<IBinding, TestBinding>();
services.AddSingleton<IBinding, ConfigBinding>();
services.AddSingleton<IBinding, AccountBinding>();

services.AddSingleton<IBinding>(sp => sp.GetRequiredService<IBasicConnectorBinding>());
services.AddSingleton<IBasicConnectorBinding, CSiSharedBasicConnectorBinding>();
services.AddSingleton<IAppIdleManager, CSiIdleManager>();
services.AddSingleton<IBasicConnectorBinding, CsiSharedBasicConnectorBinding>();
services.AddSingleton<IAppIdleManager, CsiIdleManager>();

services.AddSingleton<IBinding, CSiSharedSelectionBinding>();
services.AddSingleton<IBinding, CSiSharedSendBinding>();
services.AddSingleton<IBinding, CsiSharedSelectionBinding>();
services.AddSingleton<IBinding, CsiSharedSendBinding>();

services.AddScoped<ISendFilter, CSiSharedSelectionFilter>();
services.AddScoped<CSiSendCollectionManager>();
services.AddScoped<IRootObjectBuilder<ICSiWrapper>, CSiRootObjectBuilder>();
services.AddScoped<SendOperation<ICSiWrapper>>();
services.AddScoped<ISendFilter, CsiSharedSelectionFilter>();
services.AddScoped<CsiSendCollectionManager>();
services.AddScoped<IRootObjectBuilder<ICsiWrapper>, CsiRootObjectBuilder>();
services.AddScoped<SendOperation<ICsiWrapper>>();

services.RegisterTopLevelExceptionHandler();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@
<Import_RootNamespace>Speckle.Connectors.CSiShared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CSiSharedBasicConnectorBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CSiSharedSelectionBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CSiSharedSendBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Filters\CSiSharedSelectionFilter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\CSiSendCollectionManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Operations\Send\CSiRootObjectBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Plugin\CSiPluginBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Plugin\SpeckleFormBase.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CsiSharedBasicConnectorBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CsiSharedSelectionBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CsiSharedSendBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Filters\CsiSharedSelectionFilter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\CsiSendCollectionManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Operations\Send\CsiRootObjectBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Plugin\CsiPluginBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Plugin\SpeckleFormBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GlobalUsing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\CSiApplicationService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\CSiDocumentModelStore.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\CSiIdleManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\CsiApplicationService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\CsiDocumentModelStore.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\CsiIdleManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ServiceRegistration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utils\ObjectIdentifiers.cs" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Speckle.Connectors.CSiShared.Utils;
/// All API methods are based on the objectType and objectName, not the GUID.
/// We will obviously manage the GUIDs but for all method calls we need a concatenated version of the objectType and objectName.
/// Since objectType is a single int (1, 2 ... 7) we know first index will always be the objectType.
/// This int gets used by the CSiWrapperFactory to create the CSiWrappers.
/// This int gets used by the CsiWrapperFactory to create the CSiWrappers.
/// </remarks>
public static class ObjectIdentifier
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#pragma warning disable IDE0130
namespace Speckle.Connectors.ETABS21;

public class SpeckleForm : ETABSSpeckleFormBase
public class SpeckleForm : EtabsSpeckleFormBase
{
protected override HostAppVersion GetVersion() => HostAppVersion.v2021; // TODO: We need a v21
}
4 changes: 2 additions & 2 deletions Connectors/CSi/Speckle.Connectors.ETABS21/Plugin/cPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Speckle.Connectors.ETABS21;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "<Pending>")]
public class cPlugin : ETABSPluginBase
public class cPlugin : EtabsPluginBase
{
protected override ETABSSpeckleFormBase CreateETABSForm() => new SpeckleForm();
protected override EtabsSpeckleFormBase CreateEtabsForm() => new SpeckleForm();
}
Loading

0 comments on commit 196c503

Please sign in to comment.