Files
speckle-sharp-connectors/Connectors/CSi/Speckle.Connectors.CSiShared/Utils/ObjectIdentifiers.cs
T
Björn Steinhagen 196c503789 bjorn/cnx 882 send etabsobjects with their properties (#442)
* 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 <kuang.claire@gmail.com>
2024-12-11 10:08:15 +00:00

36 lines
1.3 KiB
C#

namespace Speckle.Connectors.CSiShared.Utils;
/// <summary>
/// ObjectIdentifier based on concatenating the objectType and objectName. CSi is annoying, we can't use GUIDs.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public static class ObjectIdentifier
{
public static string Encode(int objectType, string objectName)
{
if (objectType < 1 || objectType > 7) // Both ETABS and SAP2000 APIs have the same returns for objectType
{
throw new ArgumentException($"Invalid object type: {objectType}. Must be between 1 and 7.");
}
return $"{objectType}{objectName}";
}
public static (int type, string name) Decode(string encodedId)
{
if (string.IsNullOrEmpty(encodedId) || encodedId.Length < 2) // Superfluous. But rather safe than sorry
{
throw new ArgumentException($"Invalid encoded ID: {encodedId}");
}
int objectType = int.Parse(encodedId[0].ToString());
string objectName = encodedId[1..];
return (objectType, objectName);
}
}