Skip to content

Commit

Permalink
Added generation of DataTypes.md documentation.
Browse files Browse the repository at this point in the history
This file is copied to the IDS repository to complete the official
documentation suite.
  • Loading branch information
CBenghi committed May 4, 2024
1 parent 6e8748b commit 8e9d212
Show file tree
Hide file tree
Showing 5 changed files with 499 additions and 5 deletions.
26 changes: 22 additions & 4 deletions ids-lib.codegen/IdsRepo_Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ internal static bool UpdateRequiresRestart()
if (!updatables.Any())
return false;

Console.WriteLine("Updates are available from the IDS repository:");
Console.WriteLine("There are file differences between this and the IDS repository:");
foreach (var updatable in updatables)
Console.WriteLine($"- {updatable.Name}");

Console.WriteLine("Get these updates from IDS repository? (y/n)");
Console.WriteLine("Should these files be updated? (y/n)");
var k = Console.ReadKey();
Console.WriteLine();
if (k.Key != ConsoleKey.Y)
Expand All @@ -120,10 +119,29 @@ public static IEnumerable<UpdatableFile> GetAllUpdatable(DirectoryInfo solutionD
{
return UpdateDocumentationUnits(solutionDir)
.Concat(UpdateEmbeddedSchema(solutionDir))
.Concat(UpdateDataTypeDoc(solutionDir))
.Concat(UpdateTestingSchema(solutionDir));
}

private static IEnumerable<UpdatableFile> UpdateDocumentationUnits(DirectoryInfo solutionDir)
private static IEnumerable<UpdatableFile> UpdateDataTypeDoc(DirectoryInfo solutionDir)
{
var source = Path.Combine(
solutionDir.FullName,
"ids-lib.codegen",
"buildingSMART",
"DataTypes.md"
);
var sourceFile = new FileInfo(source);
var destFile = BuildingSmartRepoFiles.GetDocumentation("DataTypes.md");
if (sourceFile.Exists)
{
if (BuildingSmartRepoFiles.FilesAreIdentical(sourceFile, destFile))
yield break;
yield return new UpdatableFile("DataType documentation markdown", sourceFile.FullName, destFile.FullName);
}
}

private static IEnumerable<UpdatableFile> UpdateDocumentationUnits(DirectoryInfo solutionDir)
{
var sourceFile = BuildingSmartRepoFiles.GetDocumentation("units.md");
if (sourceFile.Exists)
Expand Down
44 changes: 44 additions & 0 deletions ids-lib.codegen/IfcSchema_DocumentationGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xbim.Common.Metadata;

namespace IdsLib.codegen
{
internal class IfcSchema_DocumentationGenerator
{
internal static string Execute(Dictionary<string, typeMetadata> dataTypeDictionary)
{
StringBuilder sb = new StringBuilder();
var schemas = new string[] { "Ifc2x3", "Ifc4", "Ifc4x3" };

foreach (var dataType in dataTypeDictionary.Values.OrderBy(x=>x.Name))
{
var checks = schemas.Select(x => dataType.Schemas.Contains(x) ? "✔️ " : "❌ ");

sb.AppendLine($"| {dataType.Name,-45} | {string.Join(" | ", checks),-24} | {dataType.XmlBackingType,-21} |");
}

var source = stub;
source = source.Replace($"<PlaceHolderTable>", sb.ToString());
return source;
// Program.Message($"no change.", ConsoleColor.Green);
}

private const string stub = @"# DataTypes
Property dataTypes can be set to any values according to the following table.
Columns of the table determine the validity of the type depending on the schema version and the required `xs:base` type for any `xs:restriction` constraint.
| dataType | Ifc2x3 | Ifc4 | Ifc4x3 | Restriction base type |
| --------------------------------------------- | ------ | ------ | ------ | --------------------- |
<PlaceHolderTable>
Please note, this document has been automatically generated via the IDS Audit Tool repository, any changes should be initiated there.
";

}
}
6 changes: 5 additions & 1 deletion ids-lib.codegen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ static void Main()
IfcSchema_DatatypeNamesGenerator.Execute(out var dataTypeDictionary),
@"ids-lib\IfcSchema\SchemaInfo.MeasureNames.g.cs") | GeneratedContentChanged;

GeneratedContentChanged = EvaluateContentChanged(
GeneratedContentChanged = EvaluateContentChanged(
IfcSchema_DocumentationGenerator.Execute(dataTypeDictionary),
@"ids-lib.codegen\buildingSMART\DataTypes.md") | GeneratedContentChanged;

GeneratedContentChanged = EvaluateContentChanged(
IfcSchema_ClassGenerator.Execute(),
@"ids-lib\IfcSchema\SchemaInfo.Schemas.g.cs") | GeneratedContentChanged;

Expand Down
Loading

0 comments on commit 8e9d212

Please sign in to comment.