-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tekla): adds component unpacker to tekla connector (#335)
* adds component unpacker to tekla connector * removes model object converter * Update ComponentUnpacker.cs * Update ComponentUnpacker.cs
- Loading branch information
1 parent
9e68b55
commit 0debe8f
Showing
7 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using TSM = Tekla.Structures.Model; |
55 changes: 55 additions & 0 deletions
55
Connectors/Tekla/Speckle.Connector.Tekla2024/HostApp/ComponentUnpacker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
Converters/Tekla/Speckle.Converter.Tekla2024/Extensions/SpeckleApplicationIdExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters