From 9feeccfb4b0e1974cfdf324b57b409a7a87d2f2b Mon Sep 17 00:00:00 2001 From: Claudio Benghi Date: Sat, 30 Mar 2024 00:20:32 +0100 Subject: [PATCH] Added and renamed small new APIs. --- SolutionTooling/BuildingSmartRepoFiles.cs | 23 --------------- .../IdsLib.IfcSchema/SchemaInfo.md | 2 +- .../SchemaInfo/TryParseIfcDataType.md | 26 +++++++++++++++++ .../IdsSchema/IdsNodes/Facets/IdsProperty.cs | 2 +- ids-lib/IdsSchema/IdsNodes/IdsSimpleValue.cs | 4 ++- ids-lib/IfcSchema/SchemaInfo.cs | 28 +++++++++++++++---- ids-lib/LibraryInformation.cs | 2 +- ids-lib/ids-lib.csproj | 2 +- ids-tool.tests/IfcSchemaTests.cs | 8 +++--- ids-tool.tests/ids-tool.tests.csproj | 3 +- ids-tool/ids-tool.csproj | 2 +- 11 files changed, 62 insertions(+), 40 deletions(-) create mode 100644 ids-lib-documentation/IdsLib.IfcSchema/SchemaInfo/TryParseIfcDataType.md diff --git a/SolutionTooling/BuildingSmartRepoFiles.cs b/SolutionTooling/BuildingSmartRepoFiles.cs index 07367fe..d30f350 100644 --- a/SolutionTooling/BuildingSmartRepoFiles.cs +++ b/SolutionTooling/BuildingSmartRepoFiles.cs @@ -8,29 +8,6 @@ namespace idsTool.tests.Helpers; public class BuildingSmartRepoFiles { - // attempts to find the root for the IfcOpenShell's test - private static string IfcOpenShellPath - { - get - { - var d = new DirectoryInfo("."); - while (d is not null) - { - var subIDS = d.GetDirectories("IfcOpenShell").FirstOrDefault(); - if (subIDS != null) - { - if ( - subIDS.GetDirectories("choco").Any() - && subIDS.GetDirectories("src").Any() - ) - return subIDS.FullName; - } - d = d.Parent; - } - return "."; - } - } - // attempts to find the root for the buildingsmart's ids standard repository private static string IdsRepoPath { diff --git a/ids-lib-documentation/IdsLib.IfcSchema/SchemaInfo.md b/ids-lib-documentation/IdsLib.IfcSchema/SchemaInfo.md index 2c448f2..305ce31 100644 --- a/ids-lib-documentation/IdsLib.IfcSchema/SchemaInfo.md +++ b/ids-lib-documentation/IdsLib.IfcSchema/SchemaInfo.md @@ -28,7 +28,7 @@ public class SchemaInfo : IEnumerable | static [AllDataTypes](SchemaInfo/AllDataTypes.md) { get; } | The names of dataType classes across all schemas. | | static [GetConcreteClassesFrom](SchemaInfo/GetConcreteClassesFrom.md)(…) | Returns a list of the concrete class names that implement a given top class. When multiple schema flags are passed the list is the non-repeating union of the values of each schema | | static [GetSchemas](SchemaInfo/GetSchemas.md)(…) | Returns the schema metadata information for the required versions. | -| static [TryParseIfcMeasure](SchemaInfo/TryParseIfcMeasure.md)(…) | Attempts to convert a string value to an instance of the IfcMeasureInformation | +| static [TryParseIfcDataType](SchemaInfo/TryParseIfcDataType.md)(…) | Attempts to convert a string value to an instance of the IfcMeasureInformation | | static [TrySearchTopClass](SchemaInfo/TrySearchTopClass.md)(…) | Attempts to identify a single top class inheritance from a list of class names | | enum [ClassAttributeMode](SchemaInfo.ClassAttributeMode.md) | Relation that allows to connect an available attribute to an entity | | struct [ClassRelationInfo](SchemaInfo.ClassRelationInfo.md) | A structure contianing information about the ways in which an attribute is related to a class | diff --git a/ids-lib-documentation/IdsLib.IfcSchema/SchemaInfo/TryParseIfcDataType.md b/ids-lib-documentation/IdsLib.IfcSchema/SchemaInfo/TryParseIfcDataType.md new file mode 100644 index 0000000..5747f43 --- /dev/null +++ b/ids-lib-documentation/IdsLib.IfcSchema/SchemaInfo/TryParseIfcDataType.md @@ -0,0 +1,26 @@ +# SchemaInfo.TryParseIfcDataType method + +Attempts to convert a string value to an instance of the IfcMeasureInformation + +```csharp +public static bool TryParseIfcDataType(string value, out IfcDataTypeInformation? found, + bool strict = true) +``` + +| parameter | description | +| --- | --- | +| value | the dataType string to parse | +| found | | +| strict | if true only accepts capitalized data, otherwise tolerates case inconsistencies | + +## Return Value + +true if a match is found + +## See Also + +* class [IfcDataTypeInformation](../IfcDataTypeInformation.md) +* class [SchemaInfo](../SchemaInfo.md) +* namespace [IdsLib.IfcSchema](../../ids-lib.md) + + diff --git a/ids-lib/IdsSchema/IdsNodes/Facets/IdsProperty.cs b/ids-lib/IdsSchema/IdsNodes/Facets/IdsProperty.cs index 9f8d291..058b36a 100644 --- a/ids-lib/IdsSchema/IdsNodes/Facets/IdsProperty.cs +++ b/ids-lib/IdsSchema/IdsNodes/Facets/IdsProperty.cs @@ -155,7 +155,7 @@ internal protected override Audit.Status PerformAudit(AuditStateInformation stat // todo: should we fail only if all the dtMatches do not hit? foreach (var dtMatch in dtMatches) { - if (SchemaInfo.TryParseIfcMeasure(dtMatch, out var fnd, false)) + if (SchemaInfo.TryParseIfcDataType(dtMatch, out var fnd, false)) { if (!string.IsNullOrEmpty(fnd.BackingType) && value is not null && value.HasXmlBaseType(out var baseType)) { diff --git a/ids-lib/IdsSchema/IdsNodes/IdsSimpleValue.cs b/ids-lib/IdsSchema/IdsNodes/IdsSimpleValue.cs index d30bf3b..6b6b3c6 100644 --- a/ids-lib/IdsSchema/IdsNodes/IdsSimpleValue.cs +++ b/ids-lib/IdsSchema/IdsNodes/IdsSimpleValue.cs @@ -49,6 +49,8 @@ public IEnumerable GetDicreteValues() yield return Content; } + private static readonly string[] emptyStringArray = new[] { "" }; + internal static bool IsNullOrEmpty(IdsXmlNode? parentNode) { if (parentNode is null) @@ -57,7 +59,7 @@ internal static bool IsNullOrEmpty(IdsXmlNode? parentNode) return frst switch { IdsSimpleValue simple => simple.Content == string.Empty, // we need a spec, if it's empty then its null or empty - XsRestriction rest => rest.TryMatch(new[] { "" }, false, out _),// if it can match an empty string then it's not a valid value spec + XsRestriction rest => rest.TryMatch(emptyStringArray, false, out _),// if it can match an empty string then it's not a valid value spec _ => true,// if it's neither, then null }; } diff --git a/ids-lib/IfcSchema/SchemaInfo.cs b/ids-lib/IfcSchema/SchemaInfo.cs index 3fc7543..bc5edb2 100644 --- a/ids-lib/IfcSchema/SchemaInfo.cs +++ b/ids-lib/IfcSchema/SchemaInfo.cs @@ -31,8 +31,9 @@ public SchemaInfo(IfcSchemaVersions schemaVersion) { Version = schemaVersion; Classes = new Dictionary(); - AttributesToAllClasses = new Dictionary(); - AttributesToTopClasses = new Dictionary(); + AttributesToAllClasses = []; + AttributesToTopClasses = []; + AttributesToValueTypes = []; PropertySets = PropertySetInfo.GetSchema(schemaVersion)!; } @@ -72,14 +73,24 @@ public ClassInfo? this[string className] } } + /// + /// Obsolete function, please use the direct replacement TryParseIfcDataType instead, with the same parameter structure + /// + /// + [Obsolete("Use TryParseIfcDataType instead")] + public static bool TryParseIfcMeasure(string value, [NotNullWhen(true)] out IfcDataTypeInformation? found, bool strict = true) + { + return TryParseIfcDataType(value, out found, strict); + } + /// /// Attempts to convert a string value to an instance of the IfcMeasureInformation /// - /// the string to parse + /// the dataType string to parse /// /// if true only accepts capitalized data, otherwise tolerates case inconsistencies /// true if a match is found - public static bool TryParseIfcMeasure(string value, [NotNullWhen(true)] out IfcDataTypeInformation? found, bool strict = true) + public static bool TryParseIfcDataType(string value, [NotNullWhen(true)] out IfcDataTypeInformation? found, bool strict = true) { if (value == null) { @@ -95,6 +106,11 @@ public static bool TryParseIfcMeasure(string value, [NotNullWhen(true)] out IfcD return found != null; } + /// + /// A selection of all the measures available in . + /// + public static IEnumerable AllMeasureInformation => AllDataTypes.Where(x => x.Measure is not null).Select(x => x.Measure!.Value); + /// /// Add a new classInfo to the collection /// @@ -410,7 +426,7 @@ internal void AddRelationType(string objClass, params string[] typeClasses) // Debug.WriteLine($"Did not find {objClass} in {Version}"); return; } - List found = new List(); + List found = new(); foreach (var typeClass in typeClasses) { var tpC = this[typeClass]; @@ -422,7 +438,7 @@ internal void AddRelationType(string objClass, params string[] typeClasses) } if (found.Any()) { - var t = $"\t\tschema.AddRelationType(\"{objClass}\", \"{found.First()}\");"; + // var t = $"\t\tschema.AddRelationType(\"{objClass}\", \"{found.First()}\");"; // Debug.WriteLine(t); // Debug.WriteLine($"{objClass} {string.Join(",", found)}"); c.AddTypeClasses(found); diff --git a/ids-lib/LibraryInformation.cs b/ids-lib/LibraryInformation.cs index 2239526..179aac8 100644 --- a/ids-lib/LibraryInformation.cs +++ b/ids-lib/LibraryInformation.cs @@ -26,5 +26,5 @@ public static class LibraryInformation /// /// Static field with hardcoded DLL version number. /// - public static string AssemblyVersion => "1.0.66"; + public static string AssemblyVersion => "1.0.67"; } diff --git a/ids-lib/ids-lib.csproj b/ids-lib/ids-lib.csproj index 4027d25..5198ccc 100644 --- a/ids-lib/ids-lib.csproj +++ b/ids-lib/ids-lib.csproj @@ -20,7 +20,7 @@ First implementation. README.md - 1.0.66 + 1.0.67 $(AssemblyVersion) $(AssemblyVersion) true diff --git a/ids-tool.tests/IfcSchemaTests.cs b/ids-tool.tests/IfcSchemaTests.cs index 75709dc..ceaf1fd 100644 --- a/ids-tool.tests/IfcSchemaTests.cs +++ b/ids-tool.tests/IfcSchemaTests.cs @@ -162,17 +162,17 @@ public void CanParseMeasure() { var badcase = measure.IfcDataTypeClassName.Replace("IFC", "Ifc"); // strict - var res = SchemaInfo.TryParseIfcMeasure(badcase, out _, true); + var res = SchemaInfo.TryParseIfcDataType(badcase, out _, true); res.Should().BeFalse($"{measure.IfcDataTypeClassName} is not capitalized"); - res = SchemaInfo.TryParseIfcMeasure($"No{measure.IfcDataTypeClassName}", out _, true); + res = SchemaInfo.TryParseIfcDataType($"No{measure.IfcDataTypeClassName}", out _, true); res.Should().BeFalse("class does not exist"); // tolerant - res = SchemaInfo.TryParseIfcMeasure(badcase, out _, false); + res = SchemaInfo.TryParseIfcDataType(badcase, out _, false); res.Should().BeTrue(); - res = SchemaInfo.TryParseIfcMeasure($"No{measure.IfcDataTypeClassName}".ToUpperInvariant(), out _, false); + res = SchemaInfo.TryParseIfcDataType($"No{measure.IfcDataTypeClassName}".ToUpperInvariant(), out _, false); res.Should().BeFalse("class does not exist"); } } diff --git a/ids-tool.tests/ids-tool.tests.csproj b/ids-tool.tests/ids-tool.tests.csproj index b6c11ba..adfd365 100644 --- a/ids-tool.tests/ids-tool.tests.csproj +++ b/ids-tool.tests/ids-tool.tests.csproj @@ -9,7 +9,8 @@ latest True XbimOpenSourceKeyFile.snk - + 1701;1702;8002 + diff --git a/ids-tool/ids-tool.csproj b/ids-tool/ids-tool.csproj index 7c2933c..75ae243 100644 --- a/ids-tool/ids-tool.csproj +++ b/ids-tool/ids-tool.csproj @@ -16,7 +16,7 @@ icon.png IDS, buildingSmart - 1.0.66 + 1.0.67 $(AssemblyVersion) $(AssemblyVersion) https://github.com/buildingSMART/IDS-Audit-tool.git