Skip to content

Commit

Permalink
update forge units package (#14480)
Browse files Browse the repository at this point in the history
* update forge units package

* Update UnitsCore.csproj

* Update UnitsCore.csproj

* update

---------

Co-authored-by: pinzart <[email protected]>
  • Loading branch information
pinzart90 and pinzart authored Oct 12, 2023
1 parent 01ef5fc commit 60dac74
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 48 deletions.
8 changes: 3 additions & 5 deletions src/Libraries/DynamoUnits/Quantity.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using Autodesk.DesignScript.Runtime;
#if NET6_0_OR_GREATER
using ForgeUnitsCLR = Autodesk.ForgeUnits;
#endif
using ForgeUnits = Autodesk.ForgeUnits;

namespace DynamoUnits
{
Expand All @@ -12,9 +10,9 @@ namespace DynamoUnits
/// </summary>
public class Quantity
{
internal readonly ForgeUnitsCLR.Quantity forgeQuantity;
internal readonly ForgeUnits.Quantity forgeQuantity;

internal Quantity(ForgeUnitsCLR.Quantity quantity)
internal Quantity(ForgeUnits.Quantity quantity)
{
this.forgeQuantity = quantity ?? throw new ArgumentNullException();
}
Expand Down
11 changes: 4 additions & 7 deletions src/Libraries/DynamoUnits/Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
using System.Collections.Generic;
using System.Text;
using Autodesk.DesignScript.Runtime;

#if NET6_0_OR_GREATER
using ForgeUnitsCLR = Autodesk.ForgeUnits;
#endif
using ForgeUnits = Autodesk.ForgeUnits;

namespace DynamoUnits
{
Expand All @@ -14,10 +11,10 @@ namespace DynamoUnits
/// </summary>
public class Symbol
{
internal readonly ForgeUnitsCLR.Symbol forgeSymbol;
internal readonly ForgeUnitsCLR.PrefixOrSuffix forgePrefixOrSuffix;
internal readonly ForgeUnits.Symbol forgeSymbol;
internal readonly ForgeUnits.PrefixOrSuffix forgePrefixOrSuffix;

internal Symbol(ForgeUnitsCLR.Symbol symbol)
internal Symbol(ForgeUnits.Symbol symbol)
{
this.forgeSymbol = symbol ?? throw new ArgumentNullException();
this.forgePrefixOrSuffix = symbol.getPrefixOrSuffix();
Expand Down
10 changes: 4 additions & 6 deletions src/Libraries/DynamoUnits/Unit.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using Autodesk.DesignScript.Runtime;
#if NET6_0_OR_GREATER
using ForgeUnitsCLR = Autodesk.ForgeUnits;
#endif
using ForgeUnits = Autodesk.ForgeUnits;

namespace DynamoUnits
{
Expand All @@ -12,9 +10,9 @@ namespace DynamoUnits
/// </summary>
public class Unit
{
internal readonly ForgeUnitsCLR.Unit forgeUnit;
internal readonly ForgeUnits.Unit forgeUnit;

internal Unit(ForgeUnitsCLR.Unit unit)
internal Unit(ForgeUnits.Unit unit)
{
this.forgeUnit = unit ?? throw new ArgumentNullException();
}
Expand All @@ -39,7 +37,7 @@ public IEnumerable<Unit> ConvertibleUnits
{
get
{
Dictionary<string, ForgeUnitsCLR.Unit> units = Utilities.ForgeUnitsEngine.getConvertibleUnits(TypeId);
Dictionary<string, ForgeUnits.Unit> units = Utilities.ForgeUnitsEngine.getConvertibleUnits(TypeId);
return Utilities.ConvertForgeUnitDictionaryToCollection(units);
}
}
Expand Down
17 changes: 8 additions & 9 deletions src/Libraries/DynamoUnits/UnitsCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
<PropertyGroup>
<NoWarn>MSB3539;CS1591;NUnit2005;NUnit2007;CS0618;CS0612;CS0672</NoWarn>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net48' ">
<Reference Include="System.Configuration" />
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
<PackageReference Include="System.Resources.Extensions" Version="5.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
<PackageReference Include="System.Resources.Extensions" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ForgeUnits.NET" Version="4.0.3" GeneratePathProperty="true">
<ExcludeAssets>build</ExcludeAssets>
<PackageReference Include="ForgeUnits.NET" Version="4.1.1" GeneratePathProperty="true">
<!--Skip copying the runtime dlls because we only need one (ForgeUnitsManaged.dll) which we copy in a task bellow.-->
<ExcludeAssets>runtime;build</ExcludeAssets>
</PackageReference>
<PackageReference Include="ForgeUnits.Schemas" Version="1.0.0" GeneratePathProperty="true" />
<PackageReference Include="ForgeUnits.Schemas" Version="1.0.1" GeneratePathProperty="true" />
</ItemGroup>
<ItemGroup>
<Content Include="DynamoUnits_DynamoCustomization.xml" />
Expand All @@ -43,6 +41,7 @@
</ItemGroup>
<Target Name="CopyFiles" BeforeTargets="Build">
<Copy SourceFiles="$(ProjectDir)DynamoUnits_DynamoCustomization.xml" DestinationFolder="$(OutputPath)" />
<Copy SourceFiles="$(PkgForgeUnits_NET)\lib\net6.0\ForgeUnitsManaged.dll" DestinationFolder="$(OutputPath)" />
</Target>
<Target Name="GenerateFiles" AfterTargets="ResolveSateliteResDeps" Condition=" '$(OS)' != 'Unix' ">
<!-- Generate customization dll -->
Expand Down
30 changes: 13 additions & 17 deletions src/Libraries/DynamoUnits/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
using System.Reflection;
using System.IO;
using System.Configuration;

#if NET6_0_OR_GREATER
using ForgeUnitsCLR = Autodesk.ForgeUnits;
using SchemasCLR = Autodesk.ForgeUnits;
#endif
using ForgeUnits = Autodesk.ForgeUnits;

namespace DynamoUnits
{
Expand All @@ -17,7 +13,7 @@ namespace DynamoUnits
/// </summary>
public static class Utilities
{
private static ForgeUnitsCLR.UnitsEngine unitsEngine;
private static ForgeUnits.UnitsEngine unitsEngine;

/// <summary>
/// Path to the directory used load the schema definitions.
Expand Down Expand Up @@ -53,8 +49,8 @@ internal static void Initialize()

try
{
unitsEngine = new ForgeUnitsCLR.UnitsEngine();
SchemasCLR.SchemaUtility.addDefinitionsFromFolder(SchemaDirectory, unitsEngine);
unitsEngine = new ForgeUnits.UnitsEngine();
ForgeUnits.SchemaUtility.addDefinitionsFromFolder(SchemaDirectory, unitsEngine);
unitsEngine.resolveSchemas();
}
catch
Expand All @@ -72,8 +68,8 @@ internal static void SetTestEngine(string testSchemaDir)
{
try
{
unitsEngine = new ForgeUnitsCLR.UnitsEngine();
SchemasCLR.SchemaUtility.addDefinitionsFromFolder(testSchemaDir, unitsEngine);
unitsEngine = new ForgeUnits.UnitsEngine();
ForgeUnits.SchemaUtility.addDefinitionsFromFolder(testSchemaDir, unitsEngine);
unitsEngine.resolveSchemas();
}
catch
Expand Down Expand Up @@ -146,7 +142,7 @@ public static double ParseExpression(string expression)
/// <summary>
/// Engine which loads schemas and is responsible for all ForgeUnit operations.
/// </summary>
internal static ForgeUnitsCLR.UnitsEngine ForgeUnitsEngine
internal static ForgeUnits.UnitsEngine ForgeUnitsEngine
{
get
{
Expand Down Expand Up @@ -205,7 +201,7 @@ public static IEnumerable<Symbol> GetAllSymbols()
/// <param name="forgeDictionary">A dictionary keyed by a forge typeID and Forge SDK Quantities as values</param>
/// <returns></returns>
internal static IEnumerable<Quantity> CovertForgeQuantityDictionaryToCollection(
Dictionary<string, ForgeUnitsCLR.Quantity> forgeDictionary)
Dictionary<string, ForgeUnits.Quantity> forgeDictionary)
{
var dynQuantities = new List<Quantity>();

Expand All @@ -229,7 +225,7 @@ internal static IEnumerable<Quantity> CovertForgeQuantityDictionaryToCollection(
/// <param name="forgeDictionary">A dictionary keyed by a forge typeID and Forge SDK Symbols as values</param>
/// <returns></returns>
internal static IEnumerable<Symbol> ConvertForgeSymbolDictionaryToCollection(
Dictionary<string, ForgeUnitsCLR.Symbol> forgeDictionary)
Dictionary<string, ForgeUnits.Symbol> forgeDictionary)
{
var dynSymbols = new List<Symbol>();

Expand All @@ -253,7 +249,7 @@ internal static IEnumerable<Symbol> ConvertForgeSymbolDictionaryToCollection(
/// <param name="forgeDictionary">A dictionary keyed by a forge typeID and Forge SDK Units as values</param>
/// <returns></returns>
internal static IEnumerable<Unit> ConvertForgeUnitDictionaryToCollection(
Dictionary<string, ForgeUnitsCLR.Unit> forgeDictionary)
Dictionary<string, ForgeUnits.Unit> forgeDictionary)
{
var dynUnits = new List<Unit>();

Expand Down Expand Up @@ -285,7 +281,7 @@ internal static Dictionary<string, Version> GetAllRegisteredQuantityVersions()
/// </summary>
/// <param name="forgeDictionary">A dictionary keyed by a forge typeID and Forge SDK Quantities as values</param>
/// <returns>A dictionary keyed by a version-less typeID and the latest registered version as value</returns>
internal static Dictionary<string, Version> GetAllRegisteredQuantityVersions(Dictionary<string, ForgeUnitsCLR.Quantity> forgeDictionary)
internal static Dictionary<string, Version> GetAllRegisteredQuantityVersions(Dictionary<string, ForgeUnits.Quantity> forgeDictionary)
{
var versionDictionary = new Dictionary<string, Version>();

Expand Down Expand Up @@ -322,7 +318,7 @@ internal static Dictionary<string, Version> GetAllLastestRegisteredSymbolVersion
/// </summary>
/// <param name="forgeDictionary">A dictionary keyed by a forge typeID and Forge SDK Symbols as values</param>
/// <returns>A dictionary keyed by a version-less typeID and the latest registered version as value</returns>
internal static Dictionary<string, Version> GetAllLastestRegisteredSymbolVersions(Dictionary<string, ForgeUnitsCLR.Symbol> forgeDictionary)
internal static Dictionary<string, Version> GetAllLastestRegisteredSymbolVersions(Dictionary<string, ForgeUnits.Symbol> forgeDictionary)
{
var versionDictionary = new Dictionary<string, Version>();

Expand Down Expand Up @@ -359,7 +355,7 @@ internal static Dictionary<string, Version> GetAllLatestRegisteredUnitVersions()
/// </summary>
/// <param name="forgeDictionary">A dictionary keyed by a forge typeID and Forge SDK Units as values</param>
/// <returns>A dictionary keyed by a version-less typeID and the latest registered version as value</returns>
internal static Dictionary<string, Version> GetAllLatestRegisteredUnitVersions(Dictionary<string, ForgeUnitsCLR.Unit> forgeDictionary)
internal static Dictionary<string, Version> GetAllLatestRegisteredUnitVersions(Dictionary<string, ForgeUnits.Unit> forgeDictionary)
{
var versionDictionary = new Dictionary<string, Version>();

Expand Down
6 changes: 3 additions & 3 deletions test/DynamoCoreWpfTests/UnitsUITests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml;
using System.Xml;
using Dynamo.Graph;
using Dynamo.Models;
using Dynamo.Tests;
Expand All @@ -15,7 +15,7 @@

namespace DynamoCoreWpfTests
{
[TestFixture, Category("Failure")]
[TestFixture]
public class UnitsUITests : DynamoTestUIBase
{
private LengthFromString lengthFromString;
Expand Down Expand Up @@ -61,7 +61,7 @@ public void MigrateLengthFromFeetToMetersTest()

lengthFromString.MigrateLengthFromFeetToMeters(root);

string oneFeetInMeters = "0.304800000001219";
string oneFeetInMeters = "0.3048000000012192";

Assert.AreEqual(oneFeetInMeters, systemDouble.Attributes[0].Value);
}
Expand Down
2 changes: 1 addition & 1 deletion test/core/units/malformed_unit_dropdowns.dyn
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
{
"ConcreteType": "UnitsUI.Units, UnitsUI",
"SelectedIndex": 218,
"SelectedIndex": 221,
"SelectedString": "Millimeters AAA",
"NodeType": "ExtensionNode",
"Id": "2cc49d25d3b447b281a81efd6173c6cf",
Expand Down

0 comments on commit 60dac74

Please sign in to comment.