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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ repository = "https://github.com/HakanSeven12/opencaddocument"
[features]
mline-pilot = ["ifcx", "selection-storage"]
selection = []
selection-storage = ["selection", "dep:serde", "dep:rmp-serde"]
selection-storage = ["selection", "dep:serde", "dep:rmp-serde", "dep:serde_ignored", "acadrust/serde"]
serde = ["acadrust/serde", "dep:serde"]
# IFCX through the ifccad library (OpenAEC Foundation).
ifcx = ["dep:ifccad", "dep:web-time"]

[dependencies]
acadrust = { git = "https://github.com/hakanaktt/acadrust.git", rev = "c978b989a9f218e281cf923ce1d2668ee4640bd7" }
rmp-serde = { version = "=1.3.0", optional = true }
serde_ignored = { version = "=0.1.14", optional = true }
serde = { version = "1", features = ["derive"], optional = true }
# ifccad only reads and writes IFCX; the mapping to `Document` lives here.
ifccad = { git = "https://github.com/OpenAEC-Foundation/ifccad.git", rev = "207a5ad6f24f73e1e53d994d4c3ac52d1e616ab7", optional = true }
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ DWG and DXF reading and writing come from
[acadrust](https://github.com/hakanaktt/acadrust).

Enable the `selection` Cargo feature to use `selection::DocumentSelection` for
owned capture and inspection of explicit ModelSpace Line/MLINE selections,
owned capture and reconstruction of explicit Line/MLINE, Point, Circle, Arc,
Ellipse, LwPolyline, Spline, Ray and XLine selections in ModelSpace, paper layouts
and existing local block definitions, with
their layers, simple linetypes and MLINESTYLE
dependencies. It keeps separate included, external, missing and contextual
requirements. See [owned selections](docs/selection.md) and the
Expand All @@ -68,7 +70,7 @@ also enables `selection` and provides [versioned storage](docs/selection-storage
The [reconstruction API](docs/selection-reconstruction.md) builds an independent
candidate from an explicit subset and reports the result for each requested root.
The optional [MLINE preservation pilot](docs/ifcx-mline-preservation.md)
uses these APIs to save and reopen ModelSpace MLINEs in IFCCAD.
uses these APIs for MLINEs in IFCCAD. Ray/XLine adapter integration remains separate.

## Logical IFCCAD conversion

Expand Down
13 changes: 12 additions & 1 deletion docs/selection-fields.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Selection capture field audit

This is the capture boundary against acadrust revision `cec07ce`. Exhaustive
This is the capture boundary against acadrust revision `c978b989a9f218e281cf923ce1d2668ee4640bd7`. Exhaustive
struct patterns in capture code force review when supported carriers acquire
new fields. These classifications concern owned capture, not a durable byte
layout or a promise to insert arbitrary values into another drawing. See
Expand All @@ -9,6 +9,12 @@ layout or a promise to insert arbitrary values into another drawing. See
| Carrier | Retained typed values | Reference/context rules and exclusions |
| --- | --- | --- |
| `Line` | start, end, thickness, normal | common fields below |
| `Point` | location, thickness, normal, x_axis_angle | common fields; PDMODE/PDSIZE drawing context |
| `Circle`, `Arc` | center, radius, thickness, normal; Arc angles | common fields |
| `Ellipse` | center, major_axis, minor_axis_ratio, start/end parameters, normal | common fields |
| `LwPolyline`, `LwVertex` | vertices, is_closed, plinegen, constant_width, elevation, thickness, normal; each location, bulge, widths, vertex_id | vertex_id is an integer identifier, not a handle |
| `Spline`, `SplineFlags` | degree, all flags, knots, control/fit points, weights, normal, tolerances, tangents, knot_parameterization, cv_frame_visible, dwg_flags1, dwg_scenario, dxf_flags | all geometry/scalars; both definitions retained in typed storage |
| `Ray`, `XLine` | base_point, direction | common fields; no surrogate finite line |
| `MLine` | flags, justification, normal, scale_factor, start_point, style_element_count, vertices | style_handle/style_name retained; separate effective style requirement |
| `MLineVertex` | position, direction, miter, segments | no reference fields |
| `MLineSegment` | parameters, area_fill_parameters | complete float bits, no sorting or regeneration |
Expand Down Expand Up @@ -63,3 +69,8 @@ Record payloads preserve original fields, while requirements retain interpreted
roles and effective defaults separately. No sanitization other than the three
declared entity storage/derived fields is allowed. New supported kinds, slots,
attachments, storage or reconstruction require their own reviewed boundary.

The common-only field guards also destructure Vector2/Vector3 and exhaustively
match Color, LineWeight and Transparency. These guards classify fields; geometry
serialization delegates directly to the existing provider model. The dependency
description is shared by capture, durable validation and resource binding.
39 changes: 37 additions & 2 deletions docs/selection-reconstruction.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Reconstructing an owned selection

`DocumentSelection::reconstruct_available` adds explicitly requested
ModelSpace Line and MLINE roots to a candidate cloned from the current Document.
supported roots to a candidate cloned from the current Document, in ModelSpace,
PaperSpace or an existing local block definition.
Enable the `selection` Cargo feature to use this API.
Capture or reopen the selection before calling it. Reopening uses the
optional `selection-storage` feature.
Expand Down Expand Up @@ -75,7 +76,7 @@ the requested name in the style dictionary and in every rebound MLINE.

The creation check compares case-insensitive names against both occupied
names and existing references. New names must also fit DWG text lengths
in the target version and encoding. The check inspects typed Line and MLINE records,
in the target version and encoding. The check inspects supported typed roots,
block markers, qualified tables and constructor scaffold, including the
current layer, linetype and multiline style names in the header. A target
with an unqualified name carrier blocks creation. For instance, an existing
Expand Down Expand Up @@ -134,3 +135,37 @@ The candidate has independent drawing content. Its allocator reserves one
batch for the required entities, resources and scaffold. Reserved handles are
local to that candidate. History or preservation retention remains the
responsibility of the caller.

## Additional typed leaves

Point, Circle, Arc, Ellipse, LwPolyline, Spline, Ray and XLine use the same owner,
resource, handle and draw-order planning as Line/MLINE. Identity does not
normalize geometry. Translate delegates to the codec WCS translation, including
OCS centers and polyline elevation; directions, normals and spline tangents
are not translated. Nonfinite geometry or translated results block that root.
Checks also require nonzero normals/directions, positive Circle/Arc radius,
Ellipse ratio in (0,1], two polyline vertices and nonnegative widths. Splines
need a valid control or fit definition: degree/count/domain, monotone knots,
and empty or positive matching weights. Both source definitions remain retained.
These are admission checks, not a second geometry evaluator.

Point display mode and size must match the target bit-for-bit, with finite
sizes. A mismatch yields ContextMismatch only for Point; other roots continue.
The target header is never changed to make a Point qualify.

The pinned codec does not yet census Spline/Ray/XLine geometry. A private
reservation adapter temporarily substitutes only those handle-free geometries
with Point images carrying their exact common state, runs the unchanged codec
census, and restores the exact original shared images on success or failure.
Exhaustive field guards qualify that geometry has no extra handles. Raw backing,
common attachments, dangling references, other carriers and allocation floors
remain subject to the existing census. Nothing is inserted as a Point.

The compact physical gallery exercises all ten root kinds plus a fit-only
Spline in ModelSpace, two layouts and Inner nested in Outer. Both current outer
INSERT transforms survive moving/rotating one between capture and restoration.
Sparse SortEnts insertion is checked after DWG/DXF reopening. DWG retains the
fit-only representation; DXF may add derived control data to a fit-only spline.
The tests check the original fit points independently. Combined control/fit and
nondefault Spline metadata have typed-storage evidence, not a claim of exact
preservation of every field by every physical writer.
50 changes: 46 additions & 4 deletions docs/selection-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
The `selection-storage` Cargo feature enables `selection` and exposes
`opencaddocument::selection_storage::{encode, decode}`. A selection can be
reopened after the source drawing has been dropped. The feature uses private
DTOs and named MessagePack maps. Model Serde can be enabled separately.
DTOs for legacy payloads and the existing typed model for V4 leaves, using named
MessagePack maps. It enables the provider model Serde internally; Document Serde
remains an independent feature.

```rust
use opencaddocument::{
Expand Down Expand Up @@ -46,7 +48,7 @@ SortEnts order requires a check against the current target document.
| Offset | Size | Value |
| --- | ---: | --- |
| 0 | 8 | ASCII `OCADSEL` followed by byte `00` |
| 8 | 2 | Big-endian unsigned version, `0001`, `0002` or `0003` |
| 8 | 2 | Big-endian unsigned version, `0001`, `0002`, `0003` or `0004` |
| 10 | 1 | Selection kind, `01` |
| 11 | 4 | Big-endian unsigned body length |
| 15 | Body length | Exactly one MessagePack body |
Expand All @@ -58,7 +60,7 @@ bytes after the frame yield `TrailingData`. Invalid markers, types, tags and
map fields yield `InvalidBody`. Inconsistent selection content yields
`InvalidSelection`. The error exposes its category and a byte offset or JSON
Pointer when available. The writer selects the earliest version that supports
the owners in the selection. V1 covers ModelSpace. V2 adds `paper_space`, and
the owners and payloads in the selection. V1 covers ModelSpace. V2 adds `paper_space`, and
V3 adds `block_definition`. V2 and V3 support distinct owner handles in the
same selection. The remaining wire fields are shared with V1.

Expand All @@ -83,7 +85,8 @@ Unsigned and signed integer types have their usual bit-width bounds. A handle
`index32` use unsigned 32-bit integers. A count above that range cannot be
encoded. `char32` is a Unicode scalar encoded as an unsigned 32-bit integer.
Use string, boolean and nil markers for their respective types. Binary,
extension and physical float markers are rejected.
extension and physical float markers are rejected in V1–V3. V4 admits float64
only; float32, binary and extension markers remain rejected.

| Type | Fields in writer order |
| --- | --- |
Expand Down Expand Up @@ -193,3 +196,42 @@ version decision. The envelope selects the reader before it interprets the
payload. Re-encoding a valid alternative marker or map order yields the writer's
canonical representation. Independent V1 fixtures and their source generator live under
`tests/fixtures/selection/v1/`.

## V4 common-only leaf model

A selection containing an Entity payload uses V4, independently of its owners.
Legacy-only selections still choose V1 (ModelSpace), V2 (PaperSpace) or V3
(local definitions); their field layouts and byte fixtures are unchanged.

V4 adds the required body field `model_schema: "acadrust-leaf-1"`. Its context
adds required `point_display`, either nil or a named map with `mode: i16` and
`size: f64`. Point requires this context; without a Point it must be nil.
All other body/ledger fields keep the legacy definitions above.

The new payload tuple is `["entity", <named EntityType>]`. The eight allowed
variants are Point, Circle, Arc, Ellipse, LwPolyline, Spline, Ray and XLine.
The model uses the reviewed acadrust revision
`c978b989a9f218e281cf923ce1d2668ee4640bd7`, with externally tagged enum maps,
named struct maps, scalar flags and float64 geometry. Common raw_record,
graphic_data and has_ds_data are excluded; skipped/unknown input fields are
errors with the first ignored path. Reactors, XDATA and unsupported common
references are rejected even when they deserialize as valid model data.
An unknown schema is UnsupportedVersion; duplicate fields and unknown variants
are errors. The model schema changes only after reviewing this retained surface.

A private measurement serializer checks the complete borrowed V4 body once,
including legacy resources, map keys and requirements, against the same count,
value, text and depth limits. The bounded writer separately enforces actual
encoded bytes. The decoder preflights the complete body before model allocation;
there is no hidden binary sub-packet with an independent budget. Signed zero
and NaN payload bits are retained exactly; storage does not certify geometry.
Independent Ray/Circle fixtures and their standard-library Python author live
under `tests/fixtures/selection/v4/`.

V4 enforces these shapes recursively during deserialization: every model struct
(including vectors and struct enum variants) requires a named map. Intentional
sequences such as vertices, control points and payload tuples remain sequences.
An f64 field requires a float64 marker, even when an integer value could be
represented exactly. This also applies to Point display size; integer handles,
flags and legacy bits64 fields keep their integer representation. A shared
Serde adapter enforces these rules without an intermediate geometry tree.
25 changes: 24 additions & 1 deletion docs/selection.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Owned document selections

`selection::DocumentSelection` captures explicit `Line` and `MLine` roots in
`selection::DocumentSelection` captures explicit `Line`, `MLine`, `Point`, `Circle`, `Arc`,
`Ellipse`, `LwPolyline`, `Spline`, `Ray` and `XLine` roots in
ModelSpace, PaperSpace and local block definitions with their supported
dependencies. The selection is independent of the source `Document`.
Enable the `selection` Cargo feature for capture and reconstruction. The API
Expand Down Expand Up @@ -107,3 +108,25 @@ through `capture_report()`; there is no duplicate mutable report. A successful
capture with `Missing` requirements is intentionally incomplete and does not
promise successful reconstruction. See the [field audit](selection-fields.md)
for the exact supported boundary.

## Common-only typed families

The eight additional families use `SelectionPayload::Entity(Box<EntityType>)`:
the existing public model is the owned payload. No second geometry DTO is
maintained. Line and MLine keep their original payload variants. Other enum
variants, including Line/MLine disguised as Entity, are outside this boundary.
One dependency description defines owner, layer and linetype slots across
capture, storage validation and reconstruction; MLINE adds its style slots.

Point additionally captures PDMODE/PDSIZE in `SelectionContext.point_display`.
The context is present exactly when Point is selected. Reconstruction checks
that the destination agrees, without changing its global display settings.

The additional enum variant and public context field require updates to
external exhaustive matches and struct literals. This is a source API change;
it does not claim to compile every existing consumer unchanged.

The same explicit-resource and destination-owner API can support copying
between drawings. This extension provides the shared machinery, not a new
clipboard UI or automatic mapping of every dependency or entity family.
IFCCAD preservation of Ray/XLine is a separate adapter contribution.
30 changes: 15 additions & 15 deletions src/ifcx/table_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,21 +347,21 @@ fn named_in(

pub(super) fn format_out(writer: &Writer<'_>, source: &CellStyle) -> CellFormat {
let sets = |property| source.sets(property);
let mut margins = Margins::default();
margins.left =
(sets(P::MARGIN_LEFT) || source.margin_override_flags != 0).then_some(source.margin_left);
margins.top =
(sets(P::MARGIN_TOP) || source.margin_override_flags != 0).then_some(source.margin_top);
margins.right =
(sets(P::MARGIN_RIGHT) || source.margin_override_flags != 0).then_some(source.margin_right);
margins.bottom = (sets(P::MARGIN_BOTTOM) || source.margin_override_flags != 0)
.then_some(source.margin_bottom);
margins.horizontal_spacing = (sets(P::MARGIN_HORIZONTAL_SPACING)
|| source.margin_override_flags != 0)
.then_some(source.horizontal_spacing);
margins.vertical_spacing = (sets(P::MARGIN_VERTICAL_SPACING)
|| source.margin_override_flags != 0)
.then_some(source.vertical_spacing);
let margins = Margins {
left: (sets(P::MARGIN_LEFT) || source.margin_override_flags != 0)
.then_some(source.margin_left),
top: (sets(P::MARGIN_TOP) || source.margin_override_flags != 0)
.then_some(source.margin_top),
right: (sets(P::MARGIN_RIGHT) || source.margin_override_flags != 0)
.then_some(source.margin_right),
bottom: (sets(P::MARGIN_BOTTOM) || source.margin_override_flags != 0)
.then_some(source.margin_bottom),
horizontal_spacing: (sets(P::MARGIN_HORIZONTAL_SPACING)
|| source.margin_override_flags != 0)
.then_some(source.horizontal_spacing),
vertical_spacing: (sets(P::MARGIN_VERTICAL_SPACING) || source.margin_override_flags != 0)
.then_some(source.vertical_spacing),
};
let edges = source.applied_border_edges;
let border = |flag: Edge, value: &CellBorder| {
(edges.contains(flag) || !value.override_flags.is_empty())
Expand Down
Loading
Loading