Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ API between minor releases.
of table rows can be read in a given encoding. `TdbReadOptions.TextEncoding` now applies to them too.
- Tests of the adapter in `TdbIO.Scene.Tests`, and test runs on Linux and macOS in CI.
- `docs/versions.md`: differences between Tekla Structures versions.
- Geometry diagnostics of the scene adapter: `TdbSceneResult.GeometryDiagnostics` (`TdbGeometryDiagnostic`) reports
the parts whose proxy box has the default dimensions of 150 mm × 150 mm, because none were read from the profile
name, and the parts without a usable geometry; `TdbSceneResult.PartCount` counts the parts. The IFC, scene JSON and
HTML exports of `tdbio` warn on standard error how many parts are rectangular proxy boxes, and the last two also list
the findings. The warnings are not part of the exported data.

### Changed

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ tdbio export model.db1 viewer.html
```

Every command takes `--json` to write one JSON object instead of text. Warnings go to standard error and do not change
the exit code. The outputs above come from small synthetic files; the values are made up. Run `tdbio --help` for the
usage, and see [the command line](docs/cli.md) for every key, column and JSON property.
the exit code. The IFC, scene and HTML exports warn on standard error how many parts are drawn as proxy boxes; the
scene and HTML exports also name the parts whose box has the default dimensions and the parts with no usable geometry.
The outputs above come from small synthetic files; the values are made up. Run `tdbio --help` for the usage, and see
[the command line](docs/cli.md) for every key, column and JSON property.

| Code | Meaning |
| --- | --- |
Expand Down
20 changes: 18 additions & 2 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Usage: tdbio info <file> [--json] [--encoding ascii|utf-8|cp1251|cp1252]
| `tdbio info <file>` | every supported kind | `key: value` lines: the kind, its main values and the number of warnings. |
| `tdbio tables <file>` | model databases (`.db1`), DBV@ files | A tab-separated header line, then one line per table section. |
| `tdbio text <file>` | model databases (`.db1`) | A tab-separated header line, then one line per text chain, then one line per orphan row. |
| `tdbio export <file> [output]` | model databases (`.db1`) | The object model as JSON (default), or with an option: `--ifc` (IFC), `--scene-json` (an IOScene scene), or no format option and an `.html` output (a standalone viewer). |
| `tdbio --help`, `tdbio -h` | | The usage text, on standard output. |
| `tdbio --version` | | `tdbio <version>`, for example `tdbio 0.1.0`. |

Expand All @@ -37,6 +38,21 @@ from its extension (reports, which have no signature, are recognised by the `.xs

An option given twice is a usage error.

## Geometry warnings of an export

The IFC, scene JSON and HTML viewer exports draw every part as a rectangular proxy box between its start and end point,
with the width and height estimated from the numbers in the profile name (150 mm × 150 mm when none are read). The
estimate does not check the profile. The meshes are not decoded Tekla solids and are not made for clash detection or
exact measurement. The warnings go to standard error, so the output on standard output or in the file holds none of
them, and they do not change the exit code. The JSON export of the object model has no geometry and no such warning.

All three exports print one line with the number of proxy boxes. The scene JSON export (`--scene-json`) and the HTML
viewer export build the scene of the `TdbIO.Scene` adapter and then also print, each after a summary line, one line per
part whose box has the default dimensions and one line per part with no usable geometry (no start or end point, or a
degenerate axis). A part is named by its GUID, or `part:{id}` when it has none. Up to 20 parts per kind are listed; the
summary line counts them all, and the full list is in `TdbSceneResult.GeometryDiagnostics`. The IFC export prints only
the line with the number of boxes.

## Exit codes

| Code | Name | Meaning |
Expand All @@ -49,8 +65,8 @@ The whole output is built before anything is written, so a failing command write
message about malformed data ends with the offset of the problem, for example
`tdbio: not a recognised Tekla file at offset 0x0`.

Warnings are written after the output, one line each: `tdbio: warning: <warning>`. They name an offset or a line, never
text from the file.
Warnings are written after the output, one line each: `tdbio: warning: <warning>`. They name an offset, a line, or, for
the [geometry warnings](#geometry-warnings-of-an-export), a part by its GUID or number, never text from the file.

## info

Expand Down
11 changes: 11 additions & 0 deletions docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ High-level connected object model produced by `Db1Document.ReadModel()`:
| `ModelCoordsys` | Local coordinate system origin and scale: `Id`, `X`, `Y`, `Z`, `Length`. |
| `ModelBoltHole` | Bolt hole penetration: `No`, `PartId`, `Part`, `PointZ`, `Length`, `LongHoleDir`, `LongHoleType`, `ShorteningLength`. |

## Scene adapter

`TdbIO.Scene` (a separate package) turns a `TeklaModel` into an IOScene scene document in metres:

| Type | Use |
| --- | --- |
| `TdbSceneReader` | `Read(path, options)` and `Read(model, options)` convert a model database or an in-memory model into a scene. |
| `TdbSceneOptions` | `ModelKey`, `IncludeBolts`, `IncludeWelds`, `GenerateGeometry` (all true by default). |
| `TdbSceneResult` | `Document` (the scene), `Diagnostics` (the structural validation of the scene), `GeometryDiagnostics`, `MetresPerUnit`, `ElementCount`, `PartCount`, `ElementsWithGeometry`, `GeometryCount`. |
| `TdbGeometryDiagnostic` | One finding about the geometry of a part: `Kind` (`FallbackDimensions`, `NoGeometry`), `ElementId`, `SourceId`, `Profile`, `Message` (names the part by `SourceId`, no text from the file). Every mesh is a rectangular proxy box around the part axis, not the decoded Tekla solid, and `ElementsWithGeometry` counts them; the scene is for viewing, not for clash detection or exact measurement. A part without `FallbackDimensions` has a size estimated from the numbers in its profile name, which does not check the profile. |

## Files next to the model

| Type | Use |
Expand Down
60 changes: 58 additions & 2 deletions src/TdbIO.Cli/Cli.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
Expand Down Expand Up @@ -96,15 +97,17 @@ internal static int Run(string[] args, TextWriter stdout, TextWriter stderr)
// Everything is read before anything is written, so an error never leaves half an output.
var output = new StringWriter();
string? error = null;
var exportWarnings = new List<string>();
switch (command.Name)
{
case "info": error = Info(output, doc, command.Json); break;
case "tables": Tables(output, doc, command.Json); break;
case "export": Export(output, doc, command); break;
case "export": exportWarnings.AddRange(Export(output, doc, command)); break;
default: Text(output, doc, command.Json); break;
}
stdout.Write(output.ToString());
foreach (string warning in doc.Warnings) stderr.WriteLine($"tdbio: warning: {warning}");
foreach (string warning in exportWarnings) stderr.WriteLine($"tdbio: warning: {warning}");
if (error != null)
{
stderr.WriteLine($"tdbio: {error}");
Expand Down Expand Up @@ -376,14 +379,18 @@ private static void Text(TextWriter w, TdbDocument doc, bool json)
}
}

private static void Export(TextWriter w, TdbDocument doc, Command cmd)
private static IReadOnlyList<string> Export(TextWriter w, TdbDocument doc, Command cmd)
{
var geometryWarnings = new List<string>();
if (doc is not Db1Document db1) throw new WrongKindException($"'export' needs a model database (.db1), not {doc.Kind}.");
var model = db1.ReadModel();
model.ValidateFiniteNumbers();

if (cmd.Ifc)
{
// The parts the IFC output gives a body: those with both points.
int boxes = model.Parts.Count(part => part.StartPoint.HasValue && part.EndPoint.HasValue);
if (boxes > 0) geometryWarnings.Add(ProxyBoxWarning(boxes, model.Parts.Count));
if (cmd.OutputPath != null)
{
WriteFileAtomically(cmd.Path, cmd.OutputPath, tmp => model.WriteIfc(tmp));
Expand All @@ -408,6 +415,7 @@ private static void Export(TextWriter w, TdbDocument doc, Command cmd)
{
throw new InvalidDataException(errors[0].Message);
}
geometryWarnings.AddRange(SceneGeometryWarnings(sceneResult));
WriteFileAtomically(cmd.Path, cmd.OutputPath, tmp => HtmlViewerExporter.Save(sceneResult.Document, tmp));
}
else if (cmd.SceneJson)
Expand All @@ -421,6 +429,7 @@ private static void Export(TextWriter w, TdbDocument doc, Command cmd)
{
throw new InvalidDataException(errors[0].Message);
}
geometryWarnings.AddRange(SceneGeometryWarnings(sceneResult));
if (cmd.OutputPath != null)
{
WriteFileAtomically(cmd.Path, cmd.OutputPath, tmp =>
Expand Down Expand Up @@ -464,8 +473,55 @@ private static void Export(TextWriter w, TdbDocument doc, Command cmd)
w.WriteLine(model.ToJson(cmd.Indent));
}
}
return geometryWarnings;
}

// The warning lines for the geometry of a scene conversion: one line for the proxy boxes, then for the parts with
// fallback dimensions and for those without a usable geometry a summary line and one detail line per part, up to
// DetailLimit parts per kind. Without the 'tdbio: warning: ' prefix; the caller adds it when the lines are written to
// standard error.
private const int DetailLimit = 20;

private static string ProxyBoxWarning(int boxes, int parts) => string.Create(CultureInfo.InvariantCulture,
$"{boxes} of {parts} {Noun(parts, "part", "parts")} {Noun(boxes, "uses", "use")} rectangular proxy boxes instead of decoded Tekla solids; the meshes are for viewing, not for measurements.");

internal static IReadOnlyList<string> SceneGeometryWarnings(TdbSceneResult result)
{
var lines = new List<string>();
var fallback = new List<TdbGeometryDiagnostic>();
var none = new List<TdbGeometryDiagnostic>();
foreach (var d in result.GeometryDiagnostics)
{
switch (d.Kind)
{
case TdbGeometryDiagnosticKind.FallbackDimensions: fallback.Add(d); break;
case TdbGeometryDiagnosticKind.NoGeometry: none.Add(d); break;
}
}
// Only parts have meshes, and each mesh is a proxy box.
if (result.ElementsWithGeometry > 0) lines.Add(ProxyBoxWarning(result.ElementsWithGeometry, result.PartCount));
AddDetails(lines, fallback, Noun(fallback.Count, "part uses", "parts use") + " the default dimensions of 150x150 mm because none were read from the profile name:");
AddDetails(lines, none, Noun(none.Count, "part has", "parts have") + " no usable geometry:");
return lines;
}

// The summary of one kind of geometry findings and its per-part detail lines, capped at DetailLimit.
private static void AddDetails(List<string> lines, List<TdbGeometryDiagnostic> found, string summary)
{
if (found.Count == 0)
{
return;
}
lines.Add(string.Create(CultureInfo.InvariantCulture, $"{found.Count} {summary}"));
lines.AddRange(found.Take(DetailLimit).Select(d => " " + d.Message));
if (found.Count > DetailLimit)
{
lines.Add(string.Create(CultureInfo.InvariantCulture, $" and {found.Count - DetailLimit} more parts; the full list is in TdbSceneResult.GeometryDiagnostics."));
}
}

private static string Noun(int count, string singular, string plural) => count == 1 ? singular : plural;

private static void WriteFileAtomically(string inputPath, string outputPath, Action<string> writeAction)
{
if (AreSameFile(inputPath, outputPath))
Expand Down
28 changes: 28 additions & 0 deletions src/TdbIO.Scene/TdbGeometryDiagnostic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace TdbIO.Scene;

/// <summary>What the conversion did with the geometry of one part.</summary>
public enum TdbGeometryDiagnosticKind
{
/// <summary>No dimensions were read from the profile name and the proxy box of the part uses the default ones. A part
/// without this finding has dimensions estimated from the name, which are not a check of the profile.</summary>
FallbackDimensions,

/// <summary>The part has no usable geometry (no endpoints or a degenerate axis) and got no mesh.</summary>
NoGeometry,
}

/// <summary>One finding about the scene geometry of a part. Every mesh is a rectangular proxy box around the part axis,
/// not the decoded Tekla solid (<see cref="TdbSceneResult.ElementsWithGeometry"/> counts them, so they have no findings
/// of their own); some boxes have default dimensions and some parts get no mesh. The scene of <see cref="TdbSceneReader"/> is for viewing; it is not made for clash detection or exact measurement.</summary>
/// <param name="Kind">The kind of the finding.</param>
/// <param name="ElementId">The id of the scene element of the part.</param>
/// <param name="SourceId">The source identifier of the part: its GUID, or <c>part:{id}</c> when the GUID is empty.</param>
/// <param name="Profile">The profile name of the part, or an empty string.</param>
/// <param name="Message">The human-readable finding, ready to be written as a warning line. It names the part by
/// <paramref name="SourceId"/> and holds no text from the file.</param>
public sealed record TdbGeometryDiagnostic(
TdbGeometryDiagnosticKind Kind,
long ElementId,
string SourceId,
string Profile,
string Message);
Loading
Loading