Skip to content
Closed
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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ serde_json = { version = "1", features = ["float_roundtrip"] }
name = "xref_review"
required-features = ["ifcx", "mline-pilot"]

[[example]]
name = "preservation_geometry_gallery"
required-features = ["serde", "mline-pilot"]

[[example]]
name = "annotation_gallery"
required-features = ["ifcx"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ requirements. See [owned selections](docs/selection.md) and the
also enables `selection` and provides [versioned storage](docs/selection-storage.md).
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 for MLINEs in IFCCAD. Ray/XLine adapter integration remains separate.
The optional [typed preservation adapter](docs/ifcx-mline-preservation.md)
uses these APIs for MLINE, RAY and XLINE in IFCCAD, including PaperSpace and existing local block definitions.

## Logical IFCCAD conversion

Expand Down
46 changes: 36 additions & 10 deletions docs/ifcx-mline-preservation.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# MLINE preservation in layouts and local block definitions
# MLINE, RAY and XLINE preservation in layouts and local block definitions

Enable `mline-pilot` to capture supported MLINEs into one shared package per
Enable `mline-pilot` to capture supported MLINE, RAY and XLINE roots into one shared package per
layout or local block definition when writing IFCCAD. Each live opaque
entity has a reciprocal complete record in preservation envelope 2. Its
`storageBacking` selects a subject-free Shared record. The Shared record
uses provider `opencaddocument`, revision `mline-selection-1` and payload
schema `opencaddocument.document-selection`, kind `AdapterSnapshot`.
ModelSpace uses payload version 1, PaperSpace uses version 2, and local block
definitions use version 3.
uses provider `opencaddocument` and payload schema
`opencaddocument.document-selection`, kind `AdapterSnapshot`.
MLINE-only packages use revision `mline-selection-1`: ModelSpace uses payload
version 1, PaperSpace version 2, and local block definitions version 3.
Packages containing RAY or XLINE use revision `typed-selection-1` and payload
version 4 in every owner scope, as described below.
The bytes use the corresponding [DocumentSelection storage](selection-storage.md).

The Shared source key is the selection namespace. An entity record uses
`<namespace>/entity/<positive-decimal-source-handle>`. Import verifies the
namespace and the selected MLINE root. It requests only live opaque roots,
namespace, actual frame version, provider profile and all captured root families. It requests only live opaque roots,
with current native layer, appearance and draw order in their owning layout
or definition. A shared package is scoped to one owner. Supported style
dependencies are shared within the selection. Root-local capture diagnostics
Expand All @@ -24,15 +26,39 @@ reserved when a resource disappears. Native appearance takes precedence for
the rendered linetype once the declared binding is satisfied.

Use `Ifcx::import_ifccad_preserving` and keep its context with the editable
Document. Pass it to `Ifcx::export_ifccad_preserving` on save. Applied MLINEs
Document. Pass it to `Ifcx::export_ifccad_preserving` on save. Applied roots
are captured again from the current Document. Blocked roots keep their
original package bytes, live records and owner. Layout and block identities
follow their CAD handles during a session. A local block member is restored in
definition coordinates and all existing INSERTs use that definition with their
current transforms. Resource reuse and creation follow the existing
DocumentSelection safety rules. Save reports an error if an owner with
retained roots is unavailable. Deleting an applied MLINE removes its
retained roots is unavailable. Deleting an applied root removes its
live root; an older package retained for another root may still contain its
historical capture. The core can transport unknown provider shapes. Editable
import covers supported MLINEs in ModelSpace, PaperSpace and local block
import covers supported MLINE, RAY and XLINE roots in ModelSpace, PaperSpace and local block
definitions.


## Typed selection profile

Packages containing RAY or XLINE use provider revision `typed-selection-1`,
payload version 4 and the `acadrust-leaf-1` model schema. The provider name,
payload schema/kind and preservation envelope remain unchanged. MLINE-only
capture retains the legacy provider and owner-specific V1/V2/V3 encoding.
Mixed MLINE/RAY/XLINE roots share a V4 backing per capture owner. Import rejects
metadata/frame disagreements, unsupported families (even unclaimed roots),
duplicate root claims and cross-owner backings. It is not an unknown-provider
forwarder.

An edited live root may create a fresh package while a blocked root still needs
its original backing. Only live opaque claims grant restoration; historical
roots in that old backing cannot resurrect deleted entities. Current native
layer, appearance, linetype scale and visibility remain authoritative.

RAY/XLINE remain opaque IFCCAD entities without native geometry or finite bounds.
No synthetic endpoint or far-point bounding box is exported. Their typed CAD
geometry is reconstructed using DocumentSelection. Complex linetypes, selected
INSERTs, automatic block-closure copying and raw/private codec data remain outside
this adapter's coverage. Keep `mline-pilot` enabled for this route; feature/API
renaming is a separate compatibility change.
226 changes: 226 additions & 0 deletions examples/preservation_geometry_gallery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
use opencaddocument::ifccad::*;
use opencaddocument::{
entities::{Insert, Line, MLine, Ray, XLine},
tables::BlockRecord,
Document, EntityType, Format, Ifcx, Vector3,
};

fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let arguments = std::env::args_os().skip(1).collect::<Vec<_>>();
if arguments.first().is_some_and(|s| s == "--verify") {
return verify_saved(
&std::path::PathBuf::from(&arguments[1]),
&std::path::PathBuf::from(&arguments[2]),
);
}
let directory = std::path::PathBuf::from(
std::env::args_os()
.nth(1)
.ok_or("output directory required")?,
);
if directory.exists() && directory.read_dir()?.next().is_some() {
return Err("output directory must be empty".into());
}
std::fs::create_dir_all(&directory)?;
let mut source = Document::new();
source.header.insertion_units = 4;
source.add_layout("Sheet B")?;
let mut owners = Vec::new();
for name in ["Inner", "Outer"] {
let mut block = BlockRecord::new(name);
block.handle = source.allocate_handle();
block.block_entity_handle = source.allocate_handle();
block.block_end_handle = source.allocate_handle();
owners.push(block.handle);
source.block_records.add(block)?;
}
for scope in ["Model", "Layout1", "Sheet B", "Inner"] {
let mut roots = Vec::new();
for x in [2., 12.] {
roots.push(EntityType::Ray(Ray::new(
Vector3::new(x, 3., 0.),
Vector3::UNIT_X,
)));
}
for x in [2., 12.] {
roots.push(EntityType::XLine(XLine::new(
Vector3::new(x, 8., 0.),
Vector3::UNIT_Y,
)));
}
roots.push(EntityType::MLine(MLine::from_points(&[
Vector3::ZERO,
Vector3::new(5., 0., 0.),
])));
roots.push(EntityType::Line(Line::from_points(
Vector3::ZERO,
Vector3::new(10., 10., 0.),
)));
for mut root in roots {
match scope {
"Model" => {
source.add_entity(root)?;
}
"Inner" => {
root.common_mut().owner_handle = owners[0];
source.add_entity(root)?;
}
layout => {
source.add_entity_to_layout(root, layout)?;
}
}
}
}
let mut nested = Insert::new("Inner", Vector3::new(4., 5., 0.));
nested.common.owner_handle = owners[1];
source.add_entity(EntityType::Insert(nested))?;
for x in [50., 60.] {
source.add_entity(EntityType::Insert(Insert::new(
"Outer",
Vector3::new(x, 10., 0.),
)))?;
}
for (format, name) in [
(&opencaddocument::Dwg as &dyn Format, "source.dwg"),
(&opencaddocument::Dxf as &dyn Format, "source.dxf"),
] {
let (bytes, losses) = format.write(&source)?;
assert!(losses.is_empty(), "{losses:?}");
let (_, losses) = format.read(&bytes)?;
assert!(losses.is_empty(), "{losses:?}");
std::fs::write(directory.join(name), bytes)?;
}
let mut drawing = Ifcx.export_ifccad(&source)?.drawing;
drop(source);
let mut blocked = Vec::new();
for roots in std::iter::once(&drawing.model.entities)
.chain(drawing.paper_layouts.iter().map(|p| &p.entities))
.chain(
drawing
.blocks
.iter()
.filter(|b| b.name == "Inner")
.map(|b| &b.entities),
)
{
let roots = roots
.iter()
.filter_map(|e| e.as_opaque())
.collect::<Vec<_>>();
for index in [1, 3] {
blocked.push(roots[index].preservation_record_id);
}
}
drawing.id_counters.next_line_pattern_id = 251;
for id in blocked {
let record = drawing
.preservation
.as_mut()
.unwrap()
.records
.iter_mut()
.find(|r| r.id == id)
.unwrap();
record.bindings.push(IfccadPreservationBinding {
slot: "root-linetype".into(),
source_key: "missing-pattern".into(),
target: IfccadPreservationTarget::LinePattern(IfccadLinePatternId(250)),
});
}
let json = encode_ifccad_document(&drawing)?;
let loaded = load_ifccad_bytes(json.bytes(), Default::default())?;
let (_, context) = Ifcx.import_ifccad_preserving(loaded.document())?;
assert_eq!(context.blocked_entities().count(), 8);
std::fs::write(directory.join("gallery.ifccad"), json.bytes())?;
let cbor = encode_ifccad_cbor_document(&drawing)?;
let loaded = load_ifccad_cbor_bytes(cbor.bytes(), Default::default())?;
let (_, context) = Ifcx.import_ifccad_preserving(loaded.document())?;
assert_eq!(context.blocked_entities().count(), 8);
std::fs::write(directory.join("gallery.ifccad.cbor"), cbor.bytes())?;
Ok(())
}

fn verify_saved(
input: &std::path::Path,
output: &std::path::Path,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let original = load_ifccad_bytes(&std::fs::read(input)?, Default::default())?;
let saved = load_ifccad_bytes(&std::fs::read(output)?, Default::default())?;
let original = original.document();
let saved = saved.document();
let before = original
.preservation
.as_ref()
.ok_or("missing original preservation")?;
let after = saved
.preservation
.as_ref()
.ok_or("missing saved preservation")?;
let mut count = 0;
for record in before.records.iter().filter(|r| {
r.bindings
.iter()
.any(|b| b.target == IfccadPreservationTarget::LinePattern(IfccadLinePatternId(250)))
}) {
assert!(after.records.contains(record), "blocked record changed");
let backing = before
.records
.iter()
.find(|r| Some(r.id) == record.storage_backing)
.unwrap();
assert!(after.records.contains(backing), "blocked backing changed");
let locate = |d: &IfccadDocument| {
let mut values = Vec::new();
for (owner, entities) in std::iter::once((String::from("Model"), &d.model.entities))
.chain(
d.paper_layouts
.iter()
.map(|p| (format!("Paper:{}", p.id), &p.entities)),
)
.chain(
d.blocks
.iter()
.map(|b| (format!("Block:{}", b.id), &b.entities)),
)
{
for entity in entities {
if let Some(e) = entity.as_opaque() {
if e.preservation_record_id == record.id {
values.push((owner.clone(), e.clone()));
}
}
}
}
values
};
let expected = locate(original);
assert_eq!(expected.len(), 1);
assert_eq!(
locate(saved),
expected,
"blocked owner or opaque node changed"
);
count += 1;
}
assert_eq!(count, 8);
let (opened, context) = Ifcx.import_ifccad_preserving(saved)?;
assert_eq!(context.blocked_entities().count(), 8);
assert_eq!(
opened
.document
.entities()
.filter(|e| matches!(e, EntityType::Ray(_)))
.count(),
4
);
assert_eq!(
opened
.document
.entities()
.filter(|e| matches!(e, EntityType::XLine(_)))
.count(),
4
);
println!("saved gallery: A restored and 8 blocked B roots retained with exact owners/records/backings");
Ok(())
}
10 changes: 7 additions & 3 deletions src/ifcx/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ pub(super) fn write(writer: &mut Writer) -> Result<(), Error> {
let mut entities = Vec::new();
let members = document.entities_in_block(&record.name);
#[cfg(feature = "mline-pilot")]
let members = mline_pilot::ordered_entities(document, record.handle, members.collect());
let members =
selection_preservation::ordered_entities(document, record.handle, members.collect());
#[cfg(feature = "mline-pilot")]
let mut opaque =
mline_pilot::capture_group(writer, &members, mline_pilot::Owner::Paper(layout.handle))?;
let mut opaque = selection_preservation::capture_group(
writer,
&members,
selection_preservation::Owner::Paper(layout.handle),
)?;
for entity in members {
if let EntityType::Viewport(viewport) = entity {
if Some(viewport.common.handle) == overall {
Expand Down
Loading
Loading