Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dogukan/cnx 691 extract appropriate class properties by type #352

Merged
Merged
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

namespace Speckle.Connector.Tekla2024.Plugin;

[Plugin("Speckle")]
[Plugin("Speckle (Beta)")]
[PluginUserInterface("Speckle.Connector.Tekla2024.SpeckleTeklaPanelHost")]
[InputObjectDependency(InputObjectDependency.NOT_DEPENDENT)] // See DevDocs/InputObjectDependency.NOT_DEPENDENT.png
public class TeklaPlugin : PluginBase
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@ public class SpeckleTeklaPanelHost : PluginFormBase

public SpeckleTeklaPanelHost()
{
this.Text = "Speckle Beta";
this.Name = "Speckle Beta";
this.Text = "Speckle (Beta)";
this.Name = "Speckle (Beta)";
//TODO: Add Speckle icon
// TODO: Add thumbnail to connector
var services = new ServiceCollection();
Original file line number Diff line number Diff line change
@@ -18,7 +18,8 @@ public static IServiceCollection AddTeklaConverters(this IServiceCollection serv
serviceCollection.AddTransient<ModelObjectToSpeckleConverter>();

serviceCollection.AddScoped<DisplayValueExtractor>();
serviceCollection.AddScoped<PropertyExtractor>();
serviceCollection.AddScoped<ClassPropertyExtractor>();
serviceCollection.AddScoped<ReportPropertyExtractor>();

serviceCollection.AddRootCommon<TeklaRootToSpeckleConverter>(converterAssembly);
serviceCollection.AddApplicationConverters<TeklaToSpeckleUnitConverter, Units>(converterAssembly);
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
namespace Speckle.Converter.Tekla2024.ToSpeckle.Helpers;

public class ClassPropertyExtractor
{
public ClassPropertyExtractor() { }

public Dictionary<string, object?> GetProperties(TSM.ModelObject modelObject)
{
Dictionary<string, object?> properties = new();

switch (modelObject)
{
case TSM.Beam beam:
AddBeamProperties(beam, properties);
break;
case TSM.ContourPlate plate:
AddContourPlateProperties(plate, properties);
break;
case TSM.BoltArray boltArray:
AddBoltArrayProperties(boltArray, properties);
break;
case TSM.SingleRebar singleRebar:
AddSingleRebarProperties(singleRebar, properties);
break;
case TSM.RebarMesh rebarMesh:
AddRebarMeshProperties(rebarMesh, properties);
break;
case TSM.RebarGroup rebarGroup:
AddRebarGroupProperties(rebarGroup, properties);
break;
}

return properties;
}

private void AddBeamProperties(TSM.Beam beam, Dictionary<string, object?> properties)
{
properties["Name"] = beam.Name;
properties["profile"] = beam.Profile.ProfileString;
properties["material"] = beam.Material.MaterialString;
}

private void AddContourPlateProperties(TSM.ContourPlate plate, Dictionary<string, object?> properties)
{
properties["Name"] = plate.Name;
properties["profile"] = plate.Profile.ProfileString;
properties["material"] = plate.Material.MaterialString;
}

private void AddBoltArrayProperties(TSM.BoltArray boltArray, Dictionary<string, object?> properties)
{
properties["boltSize"] = boltArray.BoltSize.ToString();
properties["boltCount"] = boltArray.BoltPositions.Count.ToString();
properties["boltStandard"] = boltArray.BoltStandard;
}

private void AddSingleRebarProperties(TSM.SingleRebar singleRebar, Dictionary<string, object?> properties)
{
properties["name"] = singleRebar.Name;
properties["grade"] = singleRebar.Grade;
properties["size"] = singleRebar.Size;
}

private void AddRebarMeshProperties(TSM.RebarMesh rebarMesh, Dictionary<string, object?> properties)
{
properties["name"] = rebarMesh.Name;
properties["grade"] = rebarMesh.Grade;
}

private void AddRebarGroupProperties(TSM.RebarGroup rebarGroup, Dictionary<string, object?> properties)
{
properties["name"] = rebarGroup.Name;
properties["grade"] = rebarGroup.Grade;
properties["size"] = rebarGroup.Size;
}
}
Original file line number Diff line number Diff line change
@@ -7,20 +7,24 @@ namespace Speckle.Converter.Tekla2024.ToSpeckle.Helpers;
public sealed class DisplayValueExtractor
{
private readonly ITypedConverter<TSM.Solid, SOG.Mesh> _meshConverter;
private readonly IConverterSettingsStore<TeklaConversionSettings> _settingsStore;
private readonly ITypedConverter<TG.Point, SOG.Point> _pointConverter;
private readonly ITypedConverter<TG.LineSegment, SOG.Line> _lineConverter;
private readonly IConverterSettingsStore<TeklaConversionSettings> _settingsStore;
private readonly ITypedConverter<TG.Arc, SOG.Arc> _arcConverter;
private readonly ITypedConverter<TSM.Grid, IEnumerable<Base>> _gridConverter;

public DisplayValueExtractor(
ITypedConverter<TSM.Solid, SOG.Mesh> meshConverter,
ITypedConverter<TG.Point, SOG.Point> pointConverter,
ITypedConverter<TG.LineSegment, SOG.Line> lineConverter,
ITypedConverter<TG.Arc, SOG.Arc> arcConverter,
ITypedConverter<TSM.Grid, IEnumerable<Base>> gridConverter,
IConverterSettingsStore<TeklaConversionSettings> settingsStore
)
{
_meshConverter = meshConverter;
_pointConverter = pointConverter;
_lineConverter = lineConverter;
_settingsStore = settingsStore;
_lineConverter = lineConverter;
_arcConverter = arcConverter;
@@ -45,6 +49,7 @@ 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,
@@ -74,8 +79,18 @@ public IEnumerable<Base> GetDisplayValue(TSM.ModelObject modelObject)
{
yield return gridLine;
}

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;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
namespace Speckle.Converter.Tekla2024.ToSpeckle.Helpers;

public class ReportPropertyExtractor
{
private static readonly Dictionary<Type, string[]> s_typeSpecificProperties =
new()
{
{
typeof(TSM.Beam),
new[]
{
"VOLUME",
"WEIGHT",
"LENGTH",
"HEIGHT",
"WIDTH",
"AREA",
"PROFILE_TYPE",
"MATERIAL_TYPE",
"CLASS",
"PREFIX",
"ASSEMBLY_POS",
"ASSEMBLY_NAME",
"PHASE"
}
},
{
typeof(TSM.ContourPlate),
new[]
{
"VOLUME",
"WEIGHT",
"AREA",
"PROFILE_TYPE",
"MATERIAL_TYPE",
"CLASS",
"PREFIX",
"ASSEMBLY_POS",
"PHASE"
}
},
{ typeof(TSM.RebarGroup), new[] { "NUMBER_OF_REBARS", "TOTAL_LENGTH", "WEIGHT", "SIZE", "GRADE", "CLASS" } },
{ typeof(TSM.SingleRebar), new[] { "LENGTH", "WEIGHT", "SIZE", "GRADE", "CLASS" } },
{ typeof(TSM.BoltArray), new[] { "BOLT_SIZE", "NUMBER_OF_BOLTS", "BOLT_STANDARD", "BOLT_TYPE", "LENGTH" } }
};

public Dictionary<string, object?> GetProperties(TSM.ModelObject modelObject)
{
var properties = new Dictionary<string, object?>();

if (!s_typeSpecificProperties.TryGetValue(modelObject.GetType(), out var propertyNames))
{
// if no specific properties defined, return empty dictionary
return properties;
}

foreach (string propertyName in propertyNames)
{
TryGetReportProperty(modelObject, propertyName, properties);
}

return properties;
}

private void TryGetReportProperty(
TSM.ModelObject modelObject,
string propertyName,
Dictionary<string, object?> properties
)
{
double doubleValue = 0.0;
int intValue = 0;
string stringValue = "";

if (modelObject.GetReportProperty(propertyName, ref doubleValue))
{
properties[propertyName] = doubleValue;
}
else if (modelObject.GetReportProperty(propertyName, ref intValue))
{
properties[propertyName] = intValue;
}
else if (modelObject.GetReportProperty(propertyName, ref stringValue) && !string.IsNullOrEmpty(stringValue))
{
properties[propertyName] = stringValue;
}
}
}
Original file line number Diff line number Diff line change
@@ -11,17 +11,20 @@ public class ModelObjectToSpeckleConverter : IToSpeckleTopLevelConverter
{
private readonly IConverterSettingsStore<TeklaConversionSettings> _settingsStore;
private readonly DisplayValueExtractor _displayValueExtractor;
private readonly PropertyExtractor _propertyExtractor;
private readonly ClassPropertyExtractor _propertyExtractor;
private readonly ReportPropertyExtractor _reportPropertyExtractor;

public ModelObjectToSpeckleConverter(
IConverterSettingsStore<TeklaConversionSettings> settingsStore,
DisplayValueExtractor displayValueExtractor,
PropertyExtractor propertyExtractor
ClassPropertyExtractor propertyExtractor,
ReportPropertyExtractor reportPropertyExtractor
)
{
_settingsStore = settingsStore;
_displayValueExtractor = displayValueExtractor;
_propertyExtractor = propertyExtractor;
_reportPropertyExtractor = reportPropertyExtractor;
}

public Base Convert(object target)
@@ -44,13 +47,37 @@ public Base Convert(object target)
result[prop.Key] = prop.Value;
}

// get report properties
var reportProperties = GetObjectReportProperties(modelObject);
if (reportProperties.Count > 0)
{
result["properties"] = reportProperties;
}

// get display value
var displayValue = _displayValueExtractor.GetDisplayValue(modelObject).ToList();
if (displayValue.Count > 0)
{
result["displayValue"] = displayValue;
}

// get report properties
Dictionary<string, object?> GetObjectReportProperties(TSM.ModelObject modelObject)
{
Dictionary<string, object?> properties = new();

// get report properties
var reportProperties = _reportPropertyExtractor.GetProperties(modelObject);
if (reportProperties.Count > 0)
{
properties["report"] = reportProperties;
}

// POC: might add user defined properties here

return properties;
}

// get children
// POC: This logic should be same in the material unpacker in connector
List<Base> children = new();