Skip to content

Commit

Permalink
Added and renamed small new APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
CBenghi committed Mar 29, 2024
1 parent 9e4c0ee commit 9feeccf
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 40 deletions.
23 changes: 0 additions & 23 deletions SolutionTooling/BuildingSmartRepoFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion ids-lib-documentation/IdsLib.IfcSchema/SchemaInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class SchemaInfo : IEnumerable<ClassInfo>
| 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 |
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

<!-- DO NOT EDIT: generated by xmldocmd for ids-lib.dll -->
2 changes: 1 addition & 1 deletion ids-lib/IdsSchema/IdsNodes/Facets/IdsProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
4 changes: 3 additions & 1 deletion ids-lib/IdsSchema/IdsNodes/IdsSimpleValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public IEnumerable<string> GetDicreteValues()
yield return Content;
}

private static readonly string[] emptyStringArray = new[] { "" };

internal static bool IsNullOrEmpty(IdsXmlNode? parentNode)
{
if (parentNode is null)
Expand All @@ -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
};
}
Expand Down
28 changes: 22 additions & 6 deletions ids-lib/IfcSchema/SchemaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public SchemaInfo(IfcSchemaVersions schemaVersion)
{
Version = schemaVersion;
Classes = new Dictionary<string, ClassInfo>();
AttributesToAllClasses = new Dictionary<string, string[]>();
AttributesToTopClasses = new Dictionary<string, string[]>();
AttributesToAllClasses = [];
AttributesToTopClasses = [];
AttributesToValueTypes = [];
PropertySets = PropertySetInfo.GetSchema(schemaVersion)!;
}

Expand Down Expand Up @@ -72,14 +73,24 @@ public ClassInfo? this[string className]
}
}

/// <summary>
/// Obsolete function, please use the direct replacement TryParseIfcDataType instead, with the same parameter structure
/// </summary>
/// <returns></returns>
[Obsolete("Use TryParseIfcDataType instead")]
public static bool TryParseIfcMeasure(string value, [NotNullWhen(true)] out IfcDataTypeInformation? found, bool strict = true)
{
return TryParseIfcDataType(value, out found, strict);
}

/// <summary>
/// Attempts to convert a string value to an instance of the IfcMeasureInformation
/// </summary>
/// <param name="value">the string to parse</param>
/// <param name="value">the dataType string to parse</param>
/// <param name="found"></param>
/// <param name="strict">if true only accepts capitalized data, otherwise tolerates case inconsistencies</param>
/// <returns>true if a match is found</returns>
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)
{
Expand All @@ -95,6 +106,11 @@ public static bool TryParseIfcMeasure(string value, [NotNullWhen(true)] out IfcD
return found != null;
}

/// <summary>
/// A selection of all the measures available in <see cref="AllDataTypes"/>.
/// </summary>
public static IEnumerable<IfcMeasureInformation> AllMeasureInformation => AllDataTypes.Where(x => x.Measure is not null).Select(x => x.Measure!.Value);

/// <summary>
/// Add a new classInfo to the collection
/// </summary>
Expand Down Expand Up @@ -410,7 +426,7 @@ internal void AddRelationType(string objClass, params string[] typeClasses)
// Debug.WriteLine($"Did not find {objClass} in {Version}");
return;
}
List<string> found = new List<string>();
List<string> found = new();
foreach (var typeClass in typeClasses)
{
var tpC = this[typeClass];
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ids-lib/LibraryInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public static class LibraryInformation
/// <summary>
/// Static field with hardcoded DLL version number.
/// </summary>
public static string AssemblyVersion => "1.0.66";
public static string AssemblyVersion => "1.0.67";
}
2 changes: 1 addition & 1 deletion ids-lib/ids-lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReleaseNotes>First implementation.</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<!-- Github actions are setup so that when this version is bumped the nuget package is uploaded -->
<AssemblyVersion>1.0.66</AssemblyVersion>
<AssemblyVersion>1.0.67</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<Version>$(AssemblyVersion)</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
8 changes: 4 additions & 4 deletions ids-tool.tests/IfcSchemaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
3 changes: 2 additions & 1 deletion ids-tool.tests/ids-tool.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<LangVersion>latest</LangVersion>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>XbimOpenSourceKeyFile.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<NoWarn>1701;1702;8002</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
Expand Down
2 changes: 1 addition & 1 deletion ids-tool/ids-tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageIcon>icon.png</PackageIcon>
<PackageTags>IDS, buildingSmart</PackageTags>
<!-- Github actions are setup so that when this version is bumped the nuget package is uploaded -->
<AssemblyVersion>1.0.66</AssemblyVersion>
<AssemblyVersion>1.0.67</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<Version>$(AssemblyVersion)</Version>
<RepositoryUrl>https://github.com/buildingSMART/IDS-Audit-tool.git</RepositoryUrl>
Expand Down

0 comments on commit 9feeccf

Please sign in to comment.