Skip to content

Commit 880d777

Browse files
feat(etabs): add UI integration for dynamic result type selection (#1025)
* refactor: linking up results type * fix: send settings
1 parent 4387872 commit 880d777

File tree

10 files changed

+67
-16
lines changed

10 files changed

+67
-16
lines changed

Connectors/CSi/Speckle.Connectors.CSiShared/Bindings/CsiSharedSendBinding.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ await manager.Process(
6464
.Initialize(
6565
_csiConversionSettingsFactory.Create(
6666
_csiApplicationService.SapModel,
67-
_toSpeckleSettingsManager.GetLoadCasesAndCombinations(card)
67+
_toSpeckleSettingsManager.GetLoadCasesAndCombinations(card),
68+
_toSpeckleSettingsManager.GetResultTypes(card)
6869
)
6970
);
7071
},
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Speckle.Converters.CSiShared.ToSpeckle.Helpers;
3+
4+
namespace Speckle.Connectors.CSiShared.HostApp.Helpers;
5+
6+
public class CsiResultsExtractorFactory
7+
{
8+
private readonly IServiceProvider _serviceProvider;
9+
10+
public CsiResultsExtractorFactory(IServiceProvider serviceProvider)
11+
{
12+
_serviceProvider = serviceProvider;
13+
}
14+
15+
public IApplicationResultsExtractor GetExtractor(string resultsKey) =>
16+
resultsKey switch
17+
{
18+
"FrameForces" => _serviceProvider.GetRequiredService<CsiFrameForceResultsExtractor>(),
19+
_ => throw new InvalidOperationException($"{resultsKey} not accounted for in CsiResultsExtractorFactory")
20+
};
21+
}

Connectors/CSi/Speckle.Connectors.CSiShared/Operations/Send/CsiRootObjectBuilder.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Speckle.Converters.Common;
99
using Speckle.Converters.CSiShared;
1010
using Speckle.Converters.CSiShared.Extensions;
11-
using Speckle.Converters.CSiShared.ToSpeckle.Helpers;
1211
using Speckle.Converters.CSiShared.Utils;
1312
using Speckle.Sdk;
1413
using Speckle.Sdk.Logging;
@@ -41,7 +40,7 @@ public class CsiRootObjectBuilder : IRootObjectBuilder<ICsiWrapper>
4140
private readonly ISdkActivityFactory _activityFactory;
4241
private readonly ICsiApplicationService _csiApplicationService;
4342
private readonly LoadCaseManager _loadCaseManager;
44-
private readonly CsiFrameForceResultsExtractor _frameForceResultsExtractor;
43+
private readonly CsiResultsExtractorFactory _resultsExtractorFactory;
4544

4645
public CsiRootObjectBuilder(
4746
IRootToSpeckleConverter rootToSpeckleConverter,
@@ -53,7 +52,7 @@ public CsiRootObjectBuilder(
5352
ISdkActivityFactory activityFactory,
5453
ICsiApplicationService csiApplicationService,
5554
LoadCaseManager loadCaseManager,
56-
CsiFrameForceResultsExtractor frameForceResultsExtractor
55+
CsiResultsExtractorFactory resultsExtractorFactory
5756
)
5857
{
5958
_converterSettings = converterSettings;
@@ -65,7 +64,7 @@ CsiFrameForceResultsExtractor frameForceResultsExtractor
6564
_activityFactory = activityFactory;
6665
_csiApplicationService = csiApplicationService;
6766
_loadCaseManager = loadCaseManager;
68-
_frameForceResultsExtractor = frameForceResultsExtractor;
67+
_resultsExtractorFactory = resultsExtractorFactory;
6968
}
7069

7170
/// <summary>
@@ -121,24 +120,35 @@ CancellationToken cancellationToken
121120
rootObjectCollection[ProxyKeys.SECTION] = _sectionUnpacker.UnpackSections().ToList();
122121
}
123122

123+
// Extract analysis results (if applicable)
124+
// NOTE: used in the results extraction to extract results for objects being published only
124125
var objectSelectionSummary = GetObjectSummary(csiObjects);
125-
126-
// TODO: Inject correct "extractor" according to which analysis results send settings
127126
var selectedCasesAndCombinations = _converterSettings.Current.SelectedLoadCasesAndCombinations;
127+
var requestedResultTypes = _converterSettings.Current.SelectedResultTypes;
128+
128129
if (selectedCasesAndCombinations != null && selectedCasesAndCombinations.Count > 0)
129130
{
131+
if (requestedResultTypes == null || requestedResultTypes.Count == 0)
132+
{
133+
throw new SpeckleException(
134+
"No result types stipulated for the requested load cases and combinations. Adjust publish settings."
135+
);
136+
}
137+
130138
if (!_csiApplicationService.SapModel.GetModelIsLocked()) // Don't know if there's a better way to ensure analysis is run
131139
{
132140
_logger.LogError("Model unlocked. No access to analysis results.");
133141
}
134142
else
135143
{
136144
_loadCaseManager.ConfigureSelectedLoadCases(selectedCasesAndCombinations);
137-
Base analysisResults =
138-
new()
139-
{
140-
["columnForces"] = _frameForceResultsExtractor.GetResults(objectSelectionSummary[ModelObjectType.FRAME])
141-
};
145+
Base analysisResults = new();
146+
foreach (var resultType in requestedResultTypes)
147+
{
148+
var extractor = _resultsExtractorFactory.GetExtractor(resultType);
149+
var objectNames = objectSelectionSummary[extractor.TargetObjectType];
150+
analysisResults[extractor.ResultsKey] = extractor.GetResults(objectNames);
151+
}
142152
rootObjectCollection["analysisResults"] = analysisResults;
143153
}
144154
}

Connectors/CSi/Speckle.Connectors.CSiShared/ServiceRegistration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static IServiceCollection AddCsi(this IServiceCollection services)
4646
services.AddScoped<SendOperation<ICsiWrapper>>();
4747

4848
services.AddScoped<CsiMaterialPropertyExtractor>();
49+
services.AddScoped<CsiResultsExtractorFactory>();
4950
services.AddScoped<MaterialUnpacker>();
5051
services.AddScoped<IFrameSectionPropertyExtractor, CsiFrameSectionPropertyExtractor>();
5152
services.AddScoped<IShellSectionPropertyExtractor, CsiShellSectionPropertyExtractor>();

Connectors/CSi/Speckle.Connectors.CSiShared/Settings/ResultTypeSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public class ResultTypeSetting(List<string> values) : ICardSetting
88
public string? Title { get; set; } = "Result Type";
99
public string? Type { get; set; } = "array";
1010
public object? Value { get; set; } = values;
11-
public List<string>? Enum { get; set; } = new List<string> { "Joint Reactions", "Joint Displacements", };
11+
public List<string>? Enum { get; set; } = ["FrameForces"];
1212
}

Connectors/CSi/Speckle.Connectors.CSiShared/Speckle.Connectors.CSiShared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CsiSharedSelectionBinding.cs" />
1919
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CsiSharedSendBinding.cs" />
2020
<Compile Include="$(MSBuildThisFileDirectory)Filters\CsiSharedSelectionFilter.cs" />
21+
<Compile Include="$(MSBuildThisFileDirectory)HostApp\Helpers\CsiResultsExtractorFactory.cs" />
2122
<Compile Include="$(MSBuildThisFileDirectory)HostApp\MaterialUnpacker.cs" />
2223
<Compile Include="$(MSBuildThisFileDirectory)HostApp\CsiSendCollectionManager.cs" />
2324
<Compile Include="$(MSBuildThisFileDirectory)HostApp\Helpers\CsiFrameSectionPropertyExtractor.cs" />

Converters/CSi/Speckle.Converters.CSiShared/CsiConversionSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ namespace Speckle.Converters.CSiShared;
33
public record CsiConversionSettings(
44
cSapModel SapModel,
55
string SpeckleUnits,
6-
List<string>? SelectedLoadCasesAndCombinations = null
6+
List<string>? SelectedLoadCasesAndCombinations = null,
7+
List<string>? SelectedResultTypes = null
78
);

Converters/CSi/Speckle.Converters.CSiShared/CsiConversionSettingsFactory.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ IConverterSettingsStore<CsiConversionSettings> settingsStore
1111
{
1212
public CsiConversionSettings Current => settingsStore.Current;
1313

14-
public CsiConversionSettings Create(cSapModel document, List<string>? selectedLoadCasesAndCombinations = null) =>
15-
new(document, unitsConverter.ConvertOrThrow(document.GetPresentUnits()), selectedLoadCasesAndCombinations ?? []);
14+
public CsiConversionSettings Create(
15+
cSapModel document,
16+
List<string>? selectedLoadCasesAndCombinations = null,
17+
List<string>? selectedResultTypes = null
18+
) =>
19+
new(
20+
document,
21+
unitsConverter.ConvertOrThrow(document.GetPresentUnits()),
22+
selectedLoadCasesAndCombinations ?? [],
23+
selectedResultTypes ?? []
24+
);
1625
}

Converters/CSi/Speckle.Converters.CSiShared/ToSpeckle/Helpers/CsiFrameForceResultsExtractor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public sealed class CsiFrameForceResultsExtractor : IApplicationResultsExtractor
99
private readonly ResultsArrayProcessor _resultsArrayProcessor;
1010

1111
public string ResultsKey => "FrameForces";
12+
public ModelObjectType TargetObjectType => ModelObjectType.FRAME;
1213

1314
public ResultsConfiguration Configuration { get; } =
1415
new(["Elm", "LoadCase", "Wrap:ElmSta", "Wrap:StepNum"], ["P", "V2", "V3", "T", "M2", "M3"]);

Converters/CSi/Speckle.Converters.CSiShared/ToSpeckle/Helpers/IApplicationResultsExtractor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ public interface IApplicationResultsExtractor
1414
/// <example>"FrameForces", "JointReactions", "BaseReactions"</example>
1515
string ResultsKey { get; }
1616

17+
/// <summary>
18+
/// Gets the type of CSI model objects that this extractor operates on.
19+
/// Used to automatically resolve the correct object names from the selection summary.
20+
/// </summary>
21+
ModelObjectType TargetObjectType { get; }
22+
1723
/// <summary>
1824
/// Gets the configuration defining how to process raw API arrays into hierarchical structure.
1925
/// Specifies grouping hierarchy and result value keys.

0 commit comments

Comments
 (0)