Skip to content

v2.0.0-beta.6

Pre-release
Pre-release

Choose a tag to compare

@gsdali gsdali released this 14 Nov 04:22
· 14 commits to main since this release
876b9bb

Pre-release, pinned exactly to OCCTSwift 4.0.0-beta.6. A consumer only gets this by naming it; the stable line stays at v1.8.0.

Builds on a fresh resolve again (#60). v2.0.0-beta.5 asked for SwiftDXF from: "0.3.0", which SwiftPM resolves to the newest 0.x, and SwiftDXF 0.4.0's new DXF.Entity cases (.hatch, .leader) made DXFLoader's switch non-exhaustive, so beta.5 did not compile for a consumer that did not constrain SwiftDXF. The floor is now from: "0.4.0" and the loader handles the new cases. This release also adds DrawingLoader (DXF, DWG and JWW through one entry point) and reads DWG in process through the new SwiftDWG dependency, with no converter to build or find.

One entry point for 2D drawing import: DrawingLoader.read(from:options:) (#54). DXF, DWG and JWW come back as one DrawingResult: the SwiftDXF DXF.Drawing, a DrawingSource (file name, SHA-256, format and the format's own version) and DrawingWarnings as data (skipped entities by type and layer, entities and records a DWG could not read, paper space, missing or cyclic blocks, entities a non-uniform scale could not carry, undeclared units, an empty drawing). The format is told from the file's bytes (DrawingFormat.sniff), with the extension consulted only when the bytes say nothing. JWW is read by SwiftJWW and passed through its DXF writer, so a JWW insert expands like a DXF one. Block references are expanded by default (Options.expandBlocks), with the references recorded in each entity's identity. DXFLoader.readEntities(from:options:) and DWGLoader.readEntities(from:options:) take SwiftDXF's DXF.ReadOptions. The hash helper is shared (FileDigest).

DWG tests on files AutoCAD wrote (#58 item 3). Fixtures/DWG/autocad/ holds small drawings saved by AutoCAD (AC1027 and AC1032), including a DWG with the DXF AutoCAD wrote from the same drawing, taken unmodified from the acadrust repository, where they are published under MPL-2.0 (the licence and the origin are in that folder). They test the reader on files it did not write itself: the line end points, the linear dimension's definition points and rotation, the handles AutoCAD gave (2C1, 2C2, 2C3) and the names of anonymous blocks, each as the files' author documents them, and the DWG's tables against AutoCAD's own DXF of it. AC1009 to AC1024 still have no independent fixture here (SwiftDWG's own tests cover its releases).

SwiftDXF moves to from: "0.4.0". 0.4.0 carries the work behind #55, #56, #57 and #59 (see its README): DIMENSION rotation, a computed measurement and measurement that is nil when group 42 is absent, zero or negative (it was -1.0 for SolidWorks and McMaster files; use computedMeasurement for the value), the dimension style's precision and the text split into parts; Drawing.identities (the DXF handle, else the position); block references, the layer and line type tables and per-entity line types; Entity.fitted(tolerance:) for splines and ellipses; and the extrusion of arcs, circles and polylines applied. DXF.Entity gains .hatch and .leader, and DXF.Warning gains .extrusionNotApplied and .expansionTruncated, so an exhaustive switch over either needs the new cases: DXFLoader ignores hatches and leaders (no edges), and DrawingWarning.Kind gains extrusionNotApplied and expansionTruncated. HATCH and LEADER no longer appear in skipped. Identities no longer carry a # (31, A1/C1).

Tests. The same 100 x 60 plate is read from a DXF (Fixtures/Drawing/plate.dxf), the DWG and a JWW generated at test time (Support/JWWFixture.swift), and the three have the same lines and circle.

DWG: Tools/dwg2dxf is gone, SwiftDWG reads it in process (#58 item 1). DWGLoader.readEntities(from:options:) returns a DWGLoader.Conversion: the drawing in the same SwiftDXF entity model DXFLoader.readEntities returns, the source's SHA-256 and DWG version code, and warnings (what the reader could not read, an empty result). It reads through SwiftDWG (from: "0.1.0", MIT, which needs SwiftDXF 0.4.0 or later), a Swift port of ACadSharp's DWG reader with the Open Design Alliance's specification. No subprocess, no Rust toolchain, no tool to find at run time, and not macOS-only. Tools/dwg2dxf (the Rust crate on acadrust), OCCTSWIFTIO_DWG2DXF and the cargo build and cache steps in tests.yml are removed, and the DWG tests, which took a known-issue path without the converter, run unconditionally. import OCCTSwiftIO re-exports SwiftDWG's DWG namespace, as it does SwiftDXF's DXF, because a bad DWG throws DWG.Error.

  • Breaking, against main; none of it was in a release. DWGLoader.readEntities(from:converter:options:) loses converter:. Removed: DWGLoader.locateConverter, DWGLoader.converterEnvironmentVariable, DWGLoader.DWGError (catch DWG.Error: .notADWG, .unsupportedVersion, .truncated, .invalid) and DWGLoader.Conversion.converter.
  • Not breaking against main: DrawingLoader.Options.converter, DrawingSource.converter and DrawingWarning.Kind.converter. They exist only in the unmerged DrawingLoader change (#61); this change removes them before they land, because with no converter there is nothing to record in them and a field that is always nil would only mislead. DrawingSource records the file, its hash, its format and the format's version.
  • The reader now runs in your process. The subprocess contained whatever went wrong inside the converter. SwiftDWG 0.1.0 ends a corrupt file in a DWG.Error or in a drawing that counts what it lost, and is not meant to trap or never return; its README says that is checked by inverting sampled bytes of its committed drawings and of the AutoCAD samples, and not proved for every byte, so a file found to trap or hang is a bug to report. A pipeline that reads DWGs it does not trust can still run the reader out of process.
  • New: DrawingWarning.Kind.unreadable. SwiftDWG leaves out an entity, table record or block it cannot read and counts it in skipped as UNREADABLE_<type>. DrawingLoader reports each type as .unreadable (type without the prefix, OBJECT when the object has no readable type) and no longer reports it as .skippedEntities or as paper space. Blocks that are not expanded (expandBlocks: false) are counted too. A file damaged in its structure, such as an unreadable layer, line type, text style, dimension style or block control object, throws DWG.Error and is not wrapped.
  • Changed: a DWG's skipped entities have no layer. SwiftDWG writes the entities it does not model, and the ones it could not read, as bare records, so SwiftDXF counts them on layer 0 (on the layer of the INSERT, in a block that was expanded) whatever their layer was. DrawingWarning.layer is nil for a DWG, and there is one .skippedEntities warning per type.
  • Changed: releases read. SwiftDWG reads R2000 to R2018, and R14 for simple entities. R12 and earlier throw DWG.Error.unsupportedVersion; the converter's documentation said AC1009 and later, though no fixture of those releases was ever tested.
  • Unchanged: CADFileFormat has no .dwg case and ShapeLoader does not load DWG: it is an entity-level read through DrawingLoader and DWGLoader. Adding the case is source-breaking for an exhaustive switch and needs a shapes path for DWG (the DXF one reads a file, not a drawing); it is left to the maintainer (#58, "also worth deciding").
  • Tests. The two AutoCAD-written DWGs and the pair (point_object_id.dwg and the DXF AutoCAD wrote from it) from the previous entry now read through SwiftDWG, and the pair agrees on the layer, line type and dimension style tables, handles included. A truncated, damaged or newer-release file throws DWG.Error from both loaders, and a non-DWG does from DWGLoader (from DrawingLoader when the file is named .dwg), a sample of single inverted bytes of two DWGs ends in a drawing or a DWG.Error and never in a crash, and what SwiftDWG cannot read comes through as .unreadable.