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
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ jobs:
name: packages-${{ matrix.os }}
path: artifacts/*.nupkg
if-no-files-found: error

native-core:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: |
8.0.x
10.0.x
- run: dotnet build src/DwgIO.Scene/DwgIO.Scene.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path native-core-check
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ API between minor releases.
## [Unreleased]

### Added
- `DwgIO.Scene.Adapter` provides scene conversion with only DwgIO and IOScene as dependencies.
The `DwgIO.Scene` package retains its export API and forwards the existing conversion types.
- JSON and SVG export options expose a `ReportDiagnostic` callback for export warnings.
Document diagnostics cover DWG reads.
- CI builds the native engine and scene adapter with `BuildNativeCoreOnly` enabled.
- CI runs the tests on Linux and macOS as well as Windows (both target frameworks), replacing the Linux
build-only job (#34).
- `test-files/public`: the folder for committed redistributable test drawings, with the origin and licence
Expand Down
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ dotnet test
The library is in `src/DwgIO`, the CLI in `src/DwgIO.Cli`, and tests in
`tests/DwgIO.Tests`.

The engine owns DWG reading, its model and the JSON representation of the decoded drawing.
`DwgIO.Scene.Adapter` uses the public API of `DwgIO` and the IOScene contract. OBJ, GLB, SVG and HTML output
live in the existing `DwgIO.Scene` package alongside forwards for the adapter types.
Output file replacement and export diagnostics belong to the writers.

CI also builds the engine and adapter without the compatibility output code or its dependencies.
Run the compile check with a separate artifact directory.

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

Tests that need real drawings are skipped with a message when no drawing is
available. Set `DWGIO_TEST_FILES` to the folder containing your private
drawings, or place them in a `test_files` folder, to run them. The repository
Expand Down
1 change: 1 addition & 0 deletions DwgIO.slnx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Solution>
<Project Path="src/DwgIO/DwgIO.csproj" />
<Project Path="src/DwgIO.Scene.Adapter/DwgIO.Scene.Adapter.csproj" />
<Project Path="src/DwgIO.Scene/DwgIO.Scene.csproj" />
<Project Path="src/DwgIO.Cli/DwgIO.Cli.csproj" />
<Project Path="tests/DwgIO.Tests/DwgIO.Tests.csproj" />
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DwgIO is a .NET library and command line tool that reads Autodesk AutoCAD drawin
- Parses drawing metadata: summary information with custom properties and dates, application information, file dependencies and the embedded thumbnail preview.
- Lists the objects of a drawing through its handle map and decodes the geometry of LINE, CIRCLE, ARC and POINT entities.
- Writes a JSON export of the metadata, the section catalog and the decoded entities.
- Converts a drawing into a neutral [IOScene](https://www.nuget.org/packages/IOScene) scene document (`DwgIO.Scene` package): geometry in metres, ACI entity colours, one element per entity with its handle.
- Converts a drawing into a neutral [IOScene](https://www.nuget.org/packages/IOScene) scene document (`DwgIO.Scene.Adapter` package): geometry in metres, ACI entity colours, one element per entity with its handle.
- Exports the scene to Wavefront OBJ (with an MTL colour library) and binary glTF (GLB).
- Draws model space to SVG (`dwgio svg`): LINE, CIRCLE, ARC and POINT in the top view, in their ACI colours.
- Writes a standalone interactive 3D HTML viewer (`.html`): the WebGL viewer of [IOViewer](https://github.com/IOExtend/IOViewer) embedded with the scene, no server or external scripts.
Expand All @@ -29,9 +29,12 @@ and add the libraries to a .NET project:

```sh
dotnet add package DwgIO
dotnet add package DwgIO.Scene
dotnet add package DwgIO.Scene.Adapter
```

Install `DwgIO.Scene` for the existing scene API with OBJ, GLB, SVG and HTML exporters.
It includes the adapter.

The libraries target .NET 8 and .NET 10. They use managed code without native dependencies or Windows-only APIs and support Windows, Linux and macOS. Tests run on Windows, Linux and macOS.

## Command line
Expand Down Expand Up @@ -143,7 +146,8 @@ foreach (var entity in doc.Entities)

The JSON export is `DwgJsonExporter` in the `DwgIO.Json` namespace. See [Getting started](docs/getting-started.md) and [Public API](docs/public-api.md) for the supported types.

The scene export is `DwgSceneReader` in the `DwgIO.Scene` package. It converts a drawing into an `IOScene.SceneDocument` — the neutral scene model of the IOExtend tools, shared with RvtIO and NwcIO:
`DwgSceneReader` converts a drawing into an `IOScene.SceneDocument`, the neutral model shared with RvtIO and NwcIO.
The converter is available in `DwgIO.Scene.Adapter` and through the existing `DwgIO.Scene` API.

```csharp
using DwgIO.Scene;
Expand Down Expand Up @@ -171,7 +175,7 @@ The documentation site with the API reference is at <https://ioextend.github.io/
| `AcDb:AppInfo`, `AcDb:FileDepList` and `AcDb:Preview` parsing | done |
| Handle map and object stream inventory | done |
| Entity decoding: LINE, CIRCLE, ARC and POINT geometry | done (partial) |
| IOScene scene export (`DwgIO.Scene`): entities, geometry, ACI colours | done (partial) |
| IOScene scene conversion (`DwgIO.Scene.Adapter`): entities, geometry, ACI colours | done (partial) |
| OBJ and GLB export through the scene | done (partial) |
| SVG export of model space (`dwgio svg`) | done (partial) |
| Standalone HTML viewer export through IOViewer | done (partial) |
Expand Down
27 changes: 16 additions & 11 deletions docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ change in any release and is visible only to the test project through `Internals
| `DwgSummaryInfo` | Drawing properties (title, author, keywords, ...), custom properties and the created and modified dates. |
| `DwgAppInfo` | The application that saved the drawing. |
| `DwgFileDepList`, `DwgFileDependency` | External files the drawing refers to (fonts, images, references). |
| `DwgPreview`, `DwgPreviewImageKind` | The embedded thumbnail and its format (BMP, PNG or WMF). |
| `DwgPreview`, `DwgPreviewImageKind` | The embedded thumbnail and its format (BMP, PNG or WMF). `DwgDocument.PreviewReadError` provides the reason when the thumbnail section could not be read. |
| `DwgHandleMap`, `DwgHandleMapEntry` | The handle to offset index of the object stream; `Find(handle)` looks up one object. |
| `DwgObjectInfo`, `DwgHandle` | One record of the object stream: offset, size, type code (`TypeName` names it) and handle. |
| `DwgEntity`, `DwgEntityKind` | A decoded entity: handle, type, colour, linetype scale and, for LINE, CIRCLE, ARC and POINT, its `Geometry`. |
| `DwgEntity`, `DwgEntityKind` | A decoded entity with its handle, type, colour, linetype scale, `IsModelSpace` flag and the `Geometry` decoded for LINE, CIRCLE, ARC and POINT. |
| `DwgDocument.AppInfoHistory` | Decompressed bytes of `AcDb:AppInfoHistory` when available. The record layout is unknown. |
| `DwgRevHistory` | The save references of `AcDb:RevHistory`: layout version pair and one value per recorded save. |
| `DwgAuxHeader` | The auxiliary header of `AcDb:AuxHeader`: version pair, save counter, creation and last-update times, next handle. |
Expand All @@ -45,7 +45,7 @@ change in any release and is visible only to the test project through `Internals
| Type | Use |
|---|---|
| `DwgJsonExporter` | `Write(document, stream, options)` writes an opened `DwgDocument` to a stream; `WriteFile(document, path, options)` writes it to a new file. |
| `DwgJsonExportOptions` | `Indented` (default true), `IncludeSectionContents` (embeds the decompressed bytes of sections as base64; default false) and `SectionsToInclude` (names of the sections to embed; empty means every readable section). `Default` holds the default values. |
| `DwgJsonExportOptions` | `Indented` (default true), `IncludeSectionContents` (embeds the decompressed bytes of sections as base64; default false), `SectionsToInclude` (names of the sections to embed; empty means every readable section) and `ReportDiagnostic` (optional export warning receiver). `Default` holds the default values. |

```csharp
using DwgIO;
Expand All @@ -60,19 +60,23 @@ and `objects`, the numbers `pageCount` and `entityCount`, the `entities` array a
out. In `objects`, `byType` keeps hexadecimal keys and `byTypeName` gives the same counts by readable name.
For `appInfoHistory`, the export reports the byte size. Section bytes can be embedded with `IncludeSectionContents`.

## Scene export (`DwgIO.Scene` package)
## Scene conversion and export

The `DwgIO.Scene` package turns a drawing into a neutral [IOScene](https://www.nuget.org/packages/IOScene) scene
document: one model per drawing, one element per decoded entity (the handle as `SourceId`), line and point
geometries in metres, ACI colours on the placements and the conversion report in `DwgSceneResult.Diagnostics`.
Install `DwgIO.Scene.Adapter` to turn a drawing into a neutral [IOScene](https://www.nuget.org/packages/IOScene)
scene document. The adapter depends on the matching `DwgIO` version and IOScene. It produces one model per drawing
and one element per decoded entity, with its handle as `SourceId`, line and point geometry in metres,
ACI colours on placements and a report in `DwgSceneResult.Diagnostics`.

The existing `DwgIO.Scene` package includes the adapter and provides the OBJ, GLB, SVG and HTML exporters.
Both packages expose the conversion API in the `DwgIO.Scene` namespace.

| Type | Use |
|---|---|
| `DwgSceneReader` | `Read(path, options?)` opens and converts a drawing file; `Read(document, options)` converts an already opened `DwgDocument` (which needs `ModelKey`, because a document from memory has no file name). |
| `DwgSceneOptions` | `LengthUnit` (one of `mm`, `cm`, `m`, `ft`, `in`; default `m` — a DWG names no unit, so the caller chooses) and `ModelKey`. |
| `DwgSceneResult` | The `Document` (an `IOScene.SceneDocument`), `Diagnostics`, element and geometry counters, the applied `MetresPerUnit` and `UnitAssumed`. |
| `DwgSceneExport` | `SaveObj(document, objPath, options?)` writes an OBJ file with an adjacent MTL colour library; `SaveGlb(document, glbPath, options?)` writes binary glTF. Both return the conversion report; `WriteObj(scene, path)` and `WriteGlb(scene, path)` export an existing scene document. |
| `DwgSvgExporter`, `DwgSvgOptions` | Draws model space (LINE, CIRCLE, ARC, POINT) to SVG in the top view, in ACI colours, with a view box that contains every drawn entity. `WriteFile(document, path, options?)`, `Write(document, stream, options?)`. `DwgSvgOptions` holds `Scale` (pixels per drawing unit), `StrokeWidth` and `Background`. |
| `DwgSvgExporter`, `DwgSvgOptions` | Draws model space (LINE, CIRCLE, ARC, POINT) to SVG in the top view, in ACI colours, with a view box that contains every drawn entity. `WriteFile(document, path, options?)`, `Write(document, stream, options?)`. `DwgSvgOptions` holds `Scale` (pixels per drawing unit), `StrokeWidth`, `Background` and an optional `ReportDiagnostic` callback for skipped entities. |
| `DwgViewerExport` | `SaveViewer(document, htmlPath, options?, viewerOptions?)` writes a standalone interactive 3D HTML viewer (IOViewer) of the scene; `WriteViewer(scene, path, viewerOptions?)` embeds an existing scene document. |

```csharp
Expand All @@ -90,7 +94,8 @@ OBJ (with an MTL colour library) and GLB through the IOScene.Formats writers.

## Diagnostics

The library never writes to the console. Parts of a drawing that could not be decoded are listed in
`DwgDocument.Diagnostics` (section name and message) and the rest of the drawing is still read.
The library never writes to the console. `DwgDocument.Diagnostics` collects warnings and parse failures from
opening the drawing and explicit section reads. `dwgio inspect` prints the first three messages.

`dwgio inspect` prints the first three of them.
Use `DwgJsonExportOptions.ReportDiagnostic` or `DwgSvgOptions.ReportDiagnostic` to collect warnings during
export. These warnings are reported independently of the document's read diagnostics.
11 changes: 11 additions & 0 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>
<!-- Adapter and engine ship on one tag, so the packed engine dependency is exact [X.Y.Z], not >=; a mix gives NU1608. -->
<Target Name="PinProjectReferencesExactly" Condition="'$(PinProjectReferencesExactly)' == 'true'"
AfterTargets="_GetProjectReferenceVersions">
<ItemGroup>
<_Pinned Include="@(_ProjectReferencesWithVersions)"><ProjectVersion>[%(_ProjectReferencesWithVersions.ProjectVersion)]</ProjectVersion></_Pinned>
<_ProjectReferencesWithVersions Remove="@(_ProjectReferencesWithVersions)" />
<_ProjectReferencesWithVersions Include="@(_Pinned)" />
</ItemGroup>
</Target>
</Project>
1 change: 1 addition & 0 deletions src/DwgIO.Cli/DwgIO.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\Shared\AtomicOutput.cs" Link="AtomicOutput.cs" />
<InternalsVisibleTo Include="DwgIO.Tests" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/DwgIO.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;
using System.Text.Json;
using DwgIO;
using DwgIO.Internal;
using DwgIO.Output;
using DwgIO.Json;
using DwgIO.Model;
using DwgIO.Scene;
Expand Down
27 changes: 27 additions & 0 deletions src/DwgIO.Scene.Adapter/DwgIO.Scene.Adapter.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Converts a DWG drawing read by DwgIO to an IOScene document.</Description>
<PackageTags>dwg;autocad;cad;ioscene</PackageTags>
<!-- The prerelease upper bound keeps previews of the next breaking IOScene line out. -->
<NoWarn>$(NoWarn);NU5104</NoWarn>
<PinProjectReferencesExactly>true</PinProjectReferencesExactly>
</PropertyGroup>

<PropertyGroup Condition="'$(BuildNativeCoreOnly)' == 'true'">
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\DwgIO\DwgIO.csproj" />
<PackageReference Include="IOScene" />
<Compile Include="..\Shared\ArcAngles.cs;..\Shared\DwgAciPalette.cs" Link="%(Filename)%(Extension)" />
</ItemGroup>

<!-- The shared pack metadata expects icon.png beside the project; the adapter ships the engine's icon. -->
<ItemGroup>
<None Remove="$(MSBuildProjectDirectory)/icon.png" />
<None Include="..\DwgIO\icon.png" Pack="true" PackagePath="/" Visible="false" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Security.Cryptography;
using System.Text;
using DwgIO.Internal;
using DwgIO.Output;
using IOScene;
using IOScene.Formats;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Globalization;
using System.Xml;
using DwgIO.Internal;
using DwgIO.Output;
using DwgIO.Model;

namespace DwgIO.Scene;
Expand Down Expand Up @@ -50,7 +50,7 @@ public static void Write(DwgDocument document, XmlWriter writer, DwgSvgOptions?
throw new ArgumentException("DwgSvgOptions.StrokeWidth must be finite and positive.", nameof(options));
}

var shapes = Collect(document, options.Scale);
var shapes = Collect(document, options);
(double minX, double minY, double width, double height) = ViewBox(shapes);
// Margins and markers are pixel values: they stay fixed while the scale zooms the drawing.
double margin = Math.Max(0.02 * Math.Max(width, height), 8.0);
Expand Down Expand Up @@ -144,8 +144,9 @@ private sealed record SvgArc(double Cx, double Cy, double Radius, double Start,

private sealed record SvgPoint(double X, double Y, int ColorIndex) : SvgShape(ColorIndex);

private static List<SvgShape> Collect(DwgDocument document, double scale)
private static List<SvgShape> Collect(DwgDocument document, DwgSvgOptions options)
{
double scale = options.Scale;
var shapes = new List<SvgShape>();
foreach (var entity in document.Entities)
{
Expand All @@ -163,7 +164,7 @@ private static List<SvgShape> Collect(DwgDocument document, double scale)
}
else
{
Skip(document, entity, "non-finite coordinates");
Skip(options.ReportDiagnostic, entity, "non-finite coordinates");
}

break;
Expand All @@ -174,7 +175,7 @@ private static List<SvgShape> Collect(DwgDocument document, double scale)
}
else
{
Skip(document, entity, "non-finite or non-positive radius");
Skip(options.ReportDiagnostic, entity, "non-finite or non-positive radius");
}

break;
Expand All @@ -188,7 +189,7 @@ private static List<SvgShape> Collect(DwgDocument document, double scale)
}
else
{
Skip(document, entity, "non-finite or non-positive radius");
Skip(options.ReportDiagnostic, entity, "non-finite or non-positive radius");
}

break;
Expand All @@ -199,7 +200,7 @@ private static List<SvgShape> Collect(DwgDocument document, double scale)
}
else
{
Skip(document, entity, "non-finite coordinates");
Skip(options.ReportDiagnostic, entity, "non-finite coordinates");
}

break;
Expand All @@ -209,8 +210,8 @@ private static List<SvgShape> Collect(DwgDocument document, double scale)
return shapes;
}

private static void Skip(DwgDocument document, DwgEntity entity, string reason) =>
document.ReportDiagnostic($"svg: entity {entity.Handle:X} ({entity.TypeName}) skipped: {reason}");
private static void Skip(Action<string>? reportDiagnostic, DwgEntity entity, string reason) =>
reportDiagnostic?.Invoke($"svg: entity {entity.Handle:X} ({entity.TypeName}) skipped: {reason}");

private static bool IsUsable(params double[] values) => values.All(double.IsFinite);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ public sealed class DwgSvgOptions
/// <summary>Background colour, as CSS. AutoCAD renders on a dark background, but SVG files are usually
/// viewed on light ones, so the default is white and colour 7 (white/black) renders black.</summary>
public string Background { get; set; } = "white";

/// <summary>Optional receiver for skipped-entity warnings.</summary>
public Action<string>? ReportDiagnostic { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using IOViewer.Exporters;
using DwgIO.Internal;
using DwgIO.Output;
using IOScene;

namespace DwgIO.Scene;
Expand Down
Loading
Loading