-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CNX-751: Add Units to reportProperties (#389)
* Datatype Main change is the switch from Tekla.Structures.Drawing to Tekla.Structures.Datatype for units. Problem is, that Settings > Options > Units and decimals don't seem to affect API returns. Will confirm with Tekla team. Rudimentary fix applied for now. * Weight Unit * Weight Unit * Consisten representation of internal units * Distance.CurrentUnitType As discussed --------- Co-authored-by: Oğuzhan Koral <[email protected]>
- Loading branch information
1 parent
4215f90
commit 8822761
Showing
6 changed files
with
55 additions
and
44 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
10 changes: 6 additions & 4 deletions
10
Converters/Tekla/Speckle.Converters.TeklaShared/TeklaConversionSettingsFactory.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 |
---|---|---|
@@ -1,19 +1,21 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.InterfaceGenerator; | ||
using Tekla.Structures.Datatype; | ||
using Tekla.Structures.Model; | ||
using TSD = Tekla.Structures.Drawing; | ||
|
||
namespace Speckle.Converter.Tekla2024; | ||
|
||
[GenerateAutoInterface] | ||
public class TeklaConversionSettingsFactory( | ||
IHostToSpeckleUnitConverter<TSD.Units> unitsConverter, | ||
IHostToSpeckleUnitConverter<Distance.UnitType> unitsConverter, | ||
IConverterSettingsStore<TeklaConversionSettings> settingsStore | ||
) : ITeklaConversionSettingsFactory | ||
{ | ||
public TeklaConversionSettings Current => settingsStore.Current; | ||
|
||
// only handles automatic rn | ||
// NOTE: Distance.CurrentUnitType reflects Settings > Options > Units and decimals | ||
// Internal units (mm) are, however, always returned. | ||
// If model units != internal units, user can rely on units appended to each report parameter | ||
public TeklaConversionSettings Create(Model document, bool sendRebarsAsSolid) => | ||
new(document, sendRebarsAsSolid, unitsConverter.ConvertOrThrow(TSD.Units.Automatic)); | ||
new(document, sendRebarsAsSolid, unitsConverter.ConvertOrThrow(Distance.CurrentUnitType)); | ||
} |
35 changes: 12 additions & 23 deletions
35
Converters/Tekla/Speckle.Converters.TeklaShared/TeklaToSpeckleUnitConverter.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 |
---|---|---|
@@ -1,36 +1,25 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Sdk.Common.Exceptions; | ||
using Tekla.Structures.Datatype; | ||
using SSC = Speckle.Sdk.Common; | ||
using TSD = Tekla.Structures.Drawing; | ||
|
||
namespace Speckle.Converter.Tekla2024; | ||
|
||
public class TeklaToSpeckleUnitConverter : IHostToSpeckleUnitConverter<TSD.Units> | ||
public class TeklaToSpeckleUnitConverter : IHostToSpeckleUnitConverter<Distance.UnitType> | ||
{ | ||
private readonly Dictionary<TSD.Units, string> _unitMapping = new(); | ||
private readonly Dictionary<Distance.UnitType, string> _unitMapping = new(); | ||
|
||
public TeklaToSpeckleUnitConverter() | ||
{ | ||
_unitMapping[TSD.Units.Automatic] = SSC.Units.Millimeters; | ||
_unitMapping[TSD.Units.Millimeters] = SSC.Units.Millimeters; | ||
_unitMapping[TSD.Units.Centimeters] = SSC.Units.Centimeters; | ||
_unitMapping[TSD.Units.Meters] = SSC.Units.Meters; | ||
_unitMapping[TSD.Units.Inches] = SSC.Units.Inches; | ||
_unitMapping[TSD.Units.Feet] = SSC.Units.Feet; | ||
|
||
// there are also other units in tekla, not sure how to handle them in speckle | ||
// auto unit option in tekla is based on the selected environment | ||
//_unitMapping[TSD.Units.FeetAndInches] | ||
//_unitMapping[TSD.Units.CentimetersOrMeters] | ||
_unitMapping[Distance.UnitType.Millimeter] = SSC.Units.Millimeters; | ||
_unitMapping[Distance.UnitType.Centimeter] = SSC.Units.Centimeters; | ||
_unitMapping[Distance.UnitType.Meter] = SSC.Units.Meters; | ||
_unitMapping[Distance.UnitType.Inch] = SSC.Units.Inches; | ||
_unitMapping[Distance.UnitType.Foot] = SSC.Units.Feet; | ||
} | ||
|
||
public string ConvertOrThrow(TSD.Units hostUnit) | ||
{ | ||
if (_unitMapping.TryGetValue(hostUnit, out string? value)) | ||
{ | ||
return value; | ||
} | ||
|
||
throw new UnitNotSupportedException($"The Unit System \"{hostUnit}\" is unsupported."); | ||
} | ||
public string ConvertOrThrow(Distance.UnitType hostUnit) => | ||
_unitMapping.TryGetValue(hostUnit, out string? value) | ||
? value | ||
: throw new UnitNotSupportedException($"The Unit System \"{hostUnit}\" is unsupported."); | ||
} |
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
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