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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
- run: dotnet restore TdbIO.slnx
- run: dotnet build TdbIO.slnx -c Release --no-restore
- run: dotnet test TdbIO.slnx -c Release --no-build
# The native engine and its scene adapter without the IFC output (Ifc/). A separate artifact path keeps the
# regular build available; this build produces no package.
- run: dotnet build src/TdbIO.Scene/TdbIO.Scene.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path native-core-check
- if: matrix.os == 'windows-latest'
run: dotnet pack TdbIO.slnx -c Release --no-build -o artifacts
- if: matrix.os == 'windows-latest'
Expand Down
57 changes: 42 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,30 @@ jobs:
if ($env:GITHUB_REF_NAME -cne "v$($version.Trim())") {
throw "The release tag must match the package version v$($version.Trim())."
}
# Before anything is published: a commit without a changelog section for the version fails here.
- name: Extract release notes
shell: pwsh
run: |
$version = $env:GITHUB_REF_NAME.Substring(1)
$changelog = Get-Content -LiteralPath CHANGELOG.md -Encoding utf8
$start = [array]::FindIndex($changelog, [Predicate[string]] { param($line) $line.StartsWith("## [$version]") })
if ($start -lt 0) { throw "CHANGELOG.md has no entry for $version" }
$notes = @()
for ($i = $start + 1; $i -lt $changelog.Count -and -not $changelog[$i].StartsWith('## ['); $i++) { $notes += $changelog[$i] }
$notes | Set-Content -LiteralPath release-notes.md -Encoding utf8
- run: dotnet restore TdbIO.slnx
- run: dotnet build TdbIO.slnx -c Release --no-restore
- run: dotnet test TdbIO.slnx -c Release --no-build
# The script also checks the package dependencies of the scene adapter before anything is pushed.
- name: Pack release
shell: pwsh
run: ./tools/pack-release.ps1
- uses: actions/upload-artifact@v7
with:
name: packages
path: artifacts/*
- name: Create release
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$version = $env:GITHUB_REF_NAME.Substring(1)
$changelog = Get-Content -LiteralPath CHANGELOG.md -Encoding utf8
$start = [array]::FindIndex($changelog, [Predicate[string]] { param($line) $line.StartsWith("## [$version]") })
if ($start -lt 0) { throw "CHANGELOG.md has no entry for $version" }
$notes = @()
for ($i = $start + 1; $i -lt $changelog.Count -and -not $changelog[$i].StartsWith('## ['); $i++) { $notes += $changelog[$i] }
$notes | Set-Content -LiteralPath release-notes.md -Encoding utf8
$files = @(Get-ChildItem artifacts -File | ForEach-Object { $_.FullName })
gh release create $env:GITHUB_REF_NAME --title $env:GITHUB_REF_NAME --notes-file release-notes.md @files
if ($LASTEXITCODE -ne 0) { throw "gh release create failed with exit code $LASTEXITCODE" }
# The push comes before the GitHub release: a refused first publication of a package id can be fixed and the
# job run again, because --skip-duplicate makes the push repeatable and no release exists yet.
# Trusted publishing: the NuGet policy for this repository and workflow file exchanges the GitHub OIDC token for a short-lived key.
- uses: NuGet/login@v1
id: nuget-login
Expand All @@ -68,3 +67,31 @@ jobs:
dotnet nuget push $package.FullName --api-key '${{ steps.nuget-login.outputs.NUGET_API_KEY }}' --source https://api.nuget.org/v3/index.json --skip-duplicate
if ($LASTEXITCODE -ne 0) { throw "dotnet nuget push failed for $($package.Name) with exit code $LASTEXITCODE" }
}
# A release left by an earlier run of the same tag is updated, so a re-run does not fail on creating it.
- name: Create or update release
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$files = @(Get-ChildItem artifacts -File | ForEach-Object { $_.FullName })
$tagName = $env:GITHUB_REF_NAME
# A version with a hyphen is a prerelease.
$flags = @()
if ($tagName.Contains('-')) { $flags += '--prerelease' }

# Only a missing release goes on to create one; any other failure of the lookup (auth, network) stops here.
$view = gh release view $tagName 2>&1 | Out-String
if ($LASTEXITCODE -ne 0 -and $view -notmatch 'release not found') {
throw "gh release view failed with exit code ${LASTEXITCODE}: $view"
}
if ($LASTEXITCODE -eq 0) {
Write-Host "Updating existing release $tagName..."
gh release edit $tagName --notes-file release-notes.md @flags
if ($LASTEXITCODE -ne 0) { throw "gh release edit failed with exit code $LASTEXITCODE" }
gh release upload $tagName @files --clobber
if ($LASTEXITCODE -ne 0) { throw "gh release upload failed with exit code $LASTEXITCODE" }
} else {
Write-Host "Creating release $tagName..."
gh release create $tagName --verify-tag --title $tagName --notes-file release-notes.md @flags @files
if ($LASTEXITCODE -ne 0) { throw "gh release create failed with exit code $LASTEXITCODE" }
}
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,54 @@ All notable changes are documented here. The format follows [Keep a Changelog](h
and the project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html); versions before 1.0 may change the
API between minor releases.

## [Unreleased]

### Added

- `TableSection.Key` and `TableSection.Descriptors`: the key before a section and its descriptor words, as stored.
`TableRow.A` and `TableRow.B`: the two numbers after the body of a row.
- Typed decoders for the rows of the most used tables of a model database, next to the raw bytes (`ObjectRow`,
`AssemblyRow`, `PartRow`, `PointRow` and others; `TableRow.AsPart()`, `TableSection.AsParts()`).
- `Db1Document.ReadModel()`: a read-only object model (`TeklaModel`) of assemblies, parts, bolts, welds, their points and
their attributes.
- JSON output of the object model: `TeklaModel.ToJson()` and `WriteJson`, and `tdbio export model.db1 model.json`.
- IFC output of the object model: `TeklaModel.ToIfc()` and `WriteIfc` with `TeklaIfcExportOptions` (IFC2x3 and IFC4),
and `tdbio export model.db1 model.ifc`. Each straight part is approximated by a box.
- The `TdbIO.Scene` package: `TdbSceneReader` turns the object model into an IOScene scene document in metres, and
`tdbio export model.db1 model.scene.json --scene-json` writes it.
- A standalone HTML viewer of the scene: `tdbio export model.db1 viewer.html`.
- `TableRow.TextEncoding` and `Decode(ReadOnlySpan<byte>, Encoding)` on the decoded row types with text: the text values
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.

### Changed

- The IFC output of the object model is kept apart from the native engine in `src/TdbIO/Ifc`. With
`BuildNativeCoreOnly=true` the engine is compiled without it, which CI does together with `TdbIO.Scene`; the package
keeps the same public types.
- `dotnet pack` compares the public API of the library with the last published version.
- `tools/pack-release.ps1` checks that `TdbIO.Scene` depends on exactly the packed `TdbIO` version and on a released
`IOScene`. `release.yml` publishes the packages to NuGet before it creates the GitHub release, and updates a release
that an earlier run of the same tag left.
- `tdbio info` prints the values it could read when a text section is broken, and reports that error.
- `--encoding` is checked against the kind of the file before the file is opened. It applies to model databases and
DBV@ files as well as templates and reports, and `tdbio export` takes it.
- The DSTV NC reader and the template lexer stream their lines and tokens instead of holding them as lists.
- The gzip reader takes the unpacked size in the trailer as the initial size of its buffer.
- Text rows with marker `0x0C` are rejected; only `0x04` was seen in text sections.

### Fixed

- The text values of table rows are no longer required to be UTF-8. They are single-byte in the code page of the system
that saved the model, so `ReadModel()` and `tdbio export` failed with `invalid UTF-8 string` on every model saved on a
non-English system. Each value is now read as ASCII or UTF-8 when its bytes are, else in code page 1251 or 1252,
chosen once for the whole file.
- `tdbio` no longer fails with an unhandled `ArgumentException` on a path of blanks, and `tdbio info` no longer fails as
a whole when one text section of a model database is broken.
- A template reports the offset of an error as a character offset of its text, and tuple nesting is limited like block
nesting.

## [0.1.0] - 2026-11-14

First release of TdbIO.
Expand Down
42 changes: 39 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ dotnet build TdbIO.slnx -c Release
dotnet test TdbIO.slnx -c Release
```

The library is in `src/TdbIO`, the CLI in `src/TdbIO.Cli`, and tests in
`tests/TdbIO.Tests`.
The library is in `src/TdbIO`, the scene adapter in `src/TdbIO.Scene`, the CLI in
`src/TdbIO.Cli`, and tests in `tests/TdbIO.Tests` and `tests/TdbIO.Scene.Tests`.

Tests that need private inputs are skipped with a message when those
inputs are unavailable:
Expand All @@ -65,6 +65,34 @@ inputs are unavailable:

The repository ships no Tekla Structures files.

## Library boundaries

The native reader, the decoded object model and the JSON output follow the
Tekla Structures file model and live in the engine (`src/TdbIO`). The IFC
output is target-format output: its sources are in `src/TdbIO/Ifc` and are
kept apart from the native engine. The regular package keeps their
signatures and namespaces. Keep new format operations with the reader or
the model; the unit declared in an IFC file belongs to the IFC output.

`TdbIO.Scene` converts the model into an IOScene document and uses only the
public API of `TdbIO`. No engine project references an IOScene type or
another IOExtend package, and the engine grants the adapter no access to its
internals.

CI also compiles the native engine and its scene adapter without the IFC
sources. Use a separate artifact path for this compile check. It keeps the
regular build available for testing and produces no NuGet package.

```sh
dotnet build src/TdbIO.Scene/TdbIO.Scene.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path ./artifacts/native-core-check
```

`dotnet pack` compares the public API of both target frameworks with the
last published release (`PackageValidationBaselineVersion`), so a change
that breaks a consumer fails the pack. Record an intended removal in
`src/TdbIO/CompatibilitySuppressions.xml` and name it under "Breaking" in
`CHANGELOG.md`.

## Code conventions

- Follow the surrounding code and repository formatting settings.
Expand Down Expand Up @@ -92,14 +120,22 @@ compare the before and after outputs. Investigate differences and explain
intentional changes in the pull request, without naming private files or
quoting their content.

Export outputs must not change unintentionally either. Before changing the
object model, an exporter or the scene adapter, export the same input files
with the existing code (`tdbio export` as JSON, scene JSON and IFC) and keep
the results outside the repository. Export them again after the change with
the same options and compare. An IFC file holds the export time and random
identifiers of its spatial structure, so compare it with those values
replaced; JSON and scene JSON must be equal byte for byte.

## Pull requests

Include:

- A description of the problem and the change.
- Tests for behavior changes, including relevant errors and edge cases.
- The build and test commands run, their results, and any skipped checks.
- Before and after output comparison results when reading is affected.
- Before and after output comparison results when reading or an export is affected.

Do not add Tekla Structures models, customer data, vendor code, or
binaries to the repository. Keep private test files outside version
Expand Down
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ Structures: model databases (`.db1`, `.db2` and their `.bak` copies), DBV@ files
- Tells the kind of a file from its content and opens it as a typed, read-only document.
- Unpacks the gzip wrapper of model files and checks it (size, CRC-32), with a cap on the unpacked size.
- Reads the header of model databases, the id map, the text chains and the date of each save stamp.
- Walks the table sections of model databases and DBV@ files to the last byte. Rows are given as raw bytes.
- Walks the table sections of model databases and DBV@ files to the last byte. Rows are given as raw bytes, and the
rows of the most used tables of a model database also as typed values.
- Builds a read-only object model of a model database: parts, assemblies, bolts, welds, their points and attributes.
- Writes the object model as JSON, or as IFC (IFC2x3 and IFC4) with each part approximated by a box.
- Turns the object model into an IOScene scene document in metres (`TdbIO.Scene`), which the command line tool also
writes as a standalone HTML viewer.
- Reads DSTV NC parts, the block tree of templates and the pages of reports.
- Gives every value whose meaning is not known as stored, and reports values that differ from what is expected as
warnings instead of failing.
Expand All @@ -34,8 +39,12 @@ Add the library to a .NET project:
dotnet add package TdbIO
```

The library targets .NET 8 and .NET 10. It is managed code without package dependencies, native code or Windows-only
APIs.
The library targets .NET 8 and .NET 10. It uses managed code without package dependencies or native dependencies and
is tested on Windows, Linux and macOS. So that an export never overwrites its input, the command line tool asks the
operating system whether two paths name the same file (symbolic links, junctions, hard links).

`TdbIO.Scene`, the adapter from the object model to an IOScene scene document, is in this repository
(`src/TdbIO.Scene`). It is not on nuget.org yet.

## Command line

Expand Down Expand Up @@ -177,7 +186,7 @@ file name.

| Files | Kind | Read | Given raw, not decoded |
| --- | --- | --- | --- |
| `.db1`, `xslib.db1` and their `.bak` copies | `Db1` | Header (version, model GUID), id map, text sections and chains, save stamp dates, table sections and rows | Row bodies, section keys and descriptors, the two numbers after each row, the id map values, the bytes before the first table section, text bytes from 0x80 |
| `.db1`, `xslib.db1` and their `.bak` copies | `Db1` | Header (version, model GUID), id map, text sections and chains, save stamp dates, table sections and rows, typed rows of the most used tables, the object model (`ReadModel`) | Rows of the other tables, the meaning of section keys, descriptor words and of the two numbers after each row, the id map values, the bytes before the first table section, text bytes from 0x80 |
| `.db2`, `xslib.db2` and their `.bak` copies | `Db2` | Header, records with key, row count and row size | Row content |
| DBV@ files (gzip data that unpacks to `DBV@`) | `Dbv` | Name, GUID records, number lists, `C9` records, table sections and rows | Most numbers, row bodies |
| `.idrm` | `IdRanges` | Next free value, ranges | One field of each range |
Expand All @@ -194,9 +203,17 @@ Values that differ from the ones always seen are kept and reported in `Warnings`

- Version 0.1.0 is a preview. The API can change before 1.0.
- Reading only. There is no support for writing or changing files.
- The content of table rows and `.db2` rows is not decoded, so the library does not yet give parts, assemblies or other
model objects. Rows are given as raw bytes with their offsets.
- The text of model databases is given as bytes: the encoding of bytes from 0x80 is not known.
- Rows are decoded into typed values only for the most used tables of a model database. `.db2` rows and the rows of the
other tables are given as raw bytes with their offsets. The meaning of section keys, of descriptor words and of the
two numbers after each row is not established from the files.
- Part geometry is not decoded from the file. The IFC output and the scene adapter draw each straight part as a box
between its start and end point, with the width and height estimated from the profile name (150 mm × 150 mm when the
name gives none). These meshes are not Tekla solids and are not made for clash detection or exact measurement.
- The text chains of model databases are given as bytes. The text values of decoded rows are single-byte in the code
page of the system that saved the model. A value is read as ASCII or UTF-8 when its bytes are; the other values are
read in code page 1251 or 1252, chosen once for the whole file. `TdbReadOptions.TextEncoding` (`--encoding` of the
command line tool) sets the encoding instead. The choice between the two pages cannot tell Cyrillic from Latin letters
with diacritics, so give the encoding for a model saved with a Western European page.
- Drawing files are recognised but not read. Of `history.db` only the header is read.
- Only gzip data with one member, header flags 0 and nothing after the trailer is accepted.
- Templates and reports in UTF-16 are not supported. DSTV NC files must be ASCII with CR LF line breaks.
Expand Down
4 changes: 2 additions & 2 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ from its extension (reports, which have no signature, are recognised by the `.xs
| Option | Commands | Effect |
| --- | --- | --- |
| `--json` | all | Write one indented JSON object (UTF-8) instead of text. |
| `--encoding <name>` | `info` | Read a template or report with this encoding instead of detecting it: `ascii`, `utf-8`, `cp1251` or `cp1252`. The encoding is strict: a byte it does not define is an input error. Given for any other kind of file, it is a usage error. |
| `--encoding <name>` | `info`, `export` | Read a template or report, or the text values of the table rows of a model database (`.db1`) or DBV@ file, with this encoding instead of detecting it: `ascii`, `utf-8`, `cp1251` or `cp1252`. Give it for a model saved with a Western European code page, which the detection reads as `cp1251`. The encoding is strict: a byte it does not define is an input error. Given for any other kind of file, it is a usage error. |

An option given twice is a usage error.

Expand All @@ -42,7 +42,7 @@ An option given twice is a usage error.
| Code | Name | Meaning |
| --- | --- | --- |
| 0 | done | The command finished and its output was written. Warnings do not change the code. |
| 1 | usage | The command line is wrong: no command, an unknown command or option, no file, an empty file name, an extra argument, an option repeated, `--encoding` without a value or with an unknown one, or `--encoding` for a file that is not a template or report. Two lines on standard error: `tdbio: <problem>` and `Run 'tdbio --help' for usage.` |
| 1 | usage | The command line is wrong: no command, an unknown command or option, no file, an empty file name, an extra argument, an option repeated, `--encoding` without a value or with an unknown one, or `--encoding` for a file that is not a template, report, model database or DBV@ file. Two lines on standard error: `tdbio: <problem>` and `Run 'tdbio --help' for usage.` |
| 2 | input | The file cannot be used: it does not exist or cannot be read, is not recognised, is cut or malformed, is over a limit, is not supported (a drawing file, UTF-16 text), or is of a kind the command does not handle (for example `tables` on a `.nc1` file). One line on standard error, `tdbio: <problem>`, no stack trace. |

The whole output is built before anything is written, so a failing command writes nothing to standard output. A
Expand Down
Loading
Loading