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
21 changes: 19 additions & 2 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ acadrust = { git = "https://github.com/hakanaktt/acadrust.git", rev = "a7d378502
rmp-serde = { version = "=1.3.0", 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 = "9ca1cf1ff4c71dad8d380677e9eb657818b03d80", optional = true }
ifccad = { git = "https://github.com/OpenAEC-Foundation/ifccad.git", rev = "96895aea607e3f2a54f9b286115844554f59df77", optional = true }
web-time = { version = "1", optional = true }

[dev-dependencies]
serde_json = { version = "1", features = ["float_roundtrip"] }

[workspace]

[[example]]
name = "xref_review"
required-features = ["ifcx", "mline-pilot"]

[[example]]
name = "annotation_gallery"
required-features = ["ifcx"]
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ With the `ifcx` feature, the `Ifcx` format reads and writes IFCX through
[ifccad](https://github.com/OpenAEC-Foundation/ifccad):
- ifccad only reads and writes the files; the mapping to `Document` lives here,
so neither library depends on the other.
- The XREF development mapping pairs with profile 0.12.0 / CBOR 12. It retains
external DWG sources and Model attachments, with URI/search locations and
optional FileDepList identity. See [XREF scope and evidence](docs/ifcx-xrefs.md).
- The IFCX mapping covers layers, line patterns with their
SHX and text symbols, text styles, dimension styles, UCSs, the point
display, block definitions, paper layouts with their sheet and plot
Expand Down
53 changes: 53 additions & 0 deletions docs/ifcx-xrefs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# External sources and Model XREF attachments

The development mapping pairs with IFCCAD profile 0.12.0 / CBOR 12. The core
owns native source/location validation. Document maps DWG XREF definitions to
drawing-local external sources and INSERTs to native XREF placements.
`import_ifccad_preserving` and `export_ifccad_preserving` retain native source
and entity IDs, original URI spelling and optional expected FingerprintGUID.
Context history retains earlier authored locators for undo after a native save.
Resolving a file at another location does not implicitly rewrite its locator.

Supported placements are Model attachments with Z rotation and positive uniform
effective scale. The scale already includes any insertion-unit conversion.
Neither direction multiplies the unit factor again. Source base points belong
to the external source; placement is stored once as O/X/Y. Unknown offline
source units remain absent. A source definition without an INSERT is retained.
Loaded external bodies are not emitted as native blocks or Model entities.

The pure location helpers distinguish a direct URI-reference from a search
filename. Relative CAD paths map to escaped relative URI-references; drive
absolute and UNC paths map to `file:` URIs. A literal filename percent sign is
escaped once, and URI escapes are decoded once. A direct one-component relative
URI exports with `./`, keeping its direct lookup meaning on reimport. Native
URI spellings are retained in context. URI schemes without a qualified CAD
mapping, queries and fragments remain unresolved editing references; DWG/DXF
file export reports an error rather than silently changing their meaning.

DWG expected identity comes from the typed codec FileDepList using its
`Acad:XRef` feature and stored filename. Multiple matching records are an
explicit ambiguity error. The main drawing header GUID is independent.
The native expected GUID is optional and canonicalized from a valid stored
DWG GUID. `dwg_external_source_content` reads actual opened-source header
metadata; it never generates an identity.

Physical DWG tests cover AC1018, AC1021 and AC1032 dependency identity.
Physical DXF return currently has no FileDepList GUID. This matches the existing
Document/OCS DWG-to-DXF policy and adds no special GUID-loss message. This
local writer/reader evidence does not replace independent AutoCAD/ODA fixture
qualification, which remains pending in the first-slice working record.

The matched host has also been checked with LibreDWG geometry/header readback
and an independent literal FileDepList section parser. The latter is necessary
for empty fields and the legacy feature list because of identified LibreDWG
decoder limitations. An AutoCAD-authored dependency identity fixture remains
separate qualification. Extra physical dependency metadata and unbound records
produce native conversion loss diagnostics; the first native source model
retains only the qualified expected FingerprintGUID.

Overlay, arrays, Paper ownership, XREF inside a local block, nonuniform or
reflected scaling and INSERT attributes produce explicit conversion losses.
Native core validation enforces the same placement/ownership boundary.
Nested reference graphs, binding, packaging, remote download and additional
source formats remain outside this slice. The core stays independent of CAD
runtimes; Document owns CAD conversion, and the host owns resolution and I/O.
170 changes: 170 additions & 0 deletions examples/xref_review.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
//! Small XREF review project; all files pass their production reader.
use opencaddocument::{ifccad::*, *};
use std::path::PathBuf;

fn main() -> std::result::Result<(), Error> {
let root = std::env::args_os()
.nth(1)
.map(PathBuf::from)
.ok_or("output directory required")?;
let drawings = root.join("Tekeningen");
let references = root.join("Referenties");
std::fs::create_dir_all(&drawings)?;
std::fs::create_dir_all(&references)?;
let mut d = load_ifccad_bytes(
include_bytes!("../tests/fixtures/xref/attachment.ifcx"),
Default::default(),
)?
.into_document();
d.paper_layouts.clear();
let workspace = load_ifccad_bytes(
include_bytes!("../tests/fixtures/workspace-state.ifcx"),
Default::default(),
)?
.into_document();
let mut window = workspace.model_windows[0].clone();
window.id = d.id_counters.allocate_model_window_id()?;
window.view.target = ifccad::geometry_kernel::Point3::new(10000., 5500., 0.);
window.view.height = 2500.;
window.stored_ucs = IfccadUcsSelection::World;
window.use_stored_ucs = false;
window.grid.enabled = false;
d.model_view_state = Some(IfccadModelViewState {
current_model_ucs: Some(IfccadUcsSelection::World),
active_model_window_id: Some(window.id),
});
d.model_windows.push(window);
let mut source = Document::new();
source.header.insertion_units = 6;
source.header.model_space_insertion_base = Vector3::new(10., 20., 0.);
source.header.fingerprint_guid = "{E5B4A9AF-CF20-4FC9-A30F-FFB20FD987E1}".into();
source.add_entity(EntityType::Line(entities::Line::from_coords(
10., 20., 0., 12., 20., 0.,
)))?;
let (bytes, losses) = Dwg.write(&source)?;
assert!(losses.is_empty());
let (read, _) = Dwg.read(&bytes)?;
assert_eq!(
read.header.model_space_insertion_base,
source.header.model_space_insertion_base
);
std::fs::write(references.join("grondplan.dwg"), &bytes)?;
let variants = root.join("Variants");
std::fs::create_dir_all(&variants)?;
let mut other_identity = source.clone();
other_identity.header.fingerprint_guid = "{11111111-2222-3333-4444-555555555555}".into();
let (variant, losses) = Dwg.write(&other_identity)?;
assert!(losses.is_empty());
assert_eq!(
Dwg.read(&variant)?.0.header.fingerprint_guid,
other_identity.header.fingerprint_guid
);
std::fs::write(variants.join("other-guid.dwg"), variant)?;
if let Some(public) = std::env::args_os().nth(2).map(PathBuf::from) {
std::fs::create_dir_all(&public)?;
std::fs::write(public.join("xref-source.dwg"), &bytes)?;
let mut gallery = d.clone();
gallery.model_windows[0].view.target =
ifccad::geometry_kernel::Point3::new(13000., 5500., 0.);
gallery.model_windows[0].view.height = 6000.;
let prototype = gallery.model.entities[0].clone();
gallery.external_sources.clear();
gallery.model.entities.clear();
// This is a newly authored public drawing, independent of fixture history.
gallery.id_counters.next_entity_id = 1;
gallery.id_counters.next_external_source_id = 1;
gallery.id_counters.next_layout_id = gallery.model.id + 1;
let mut layers = std::collections::BTreeMap::new();
let mut next_layer = 1;
for layer in &mut gallery.layers {
let id = if layer.id == 0 {
0
} else {
let id = next_layer;
next_layer += 1;
id
};
layers.insert(layer.id, id);
layer.id = id;
}
gallery.id_counters.next_layer_id = next_layer;
if let Some(workspace) = &mut gallery.workspace_state {
workspace.current_layer_id = workspace.current_layer_id.map(|id| layers[&id]);
}
for (index, location) in [
IfccadExternalSourceLocation::UriReference {
uri: "./xref-source.dwg".into(),
},
IfccadExternalSourceLocation::SearchFileName {
file_name: "xref-source.dwg".into(),
},
IfccadExternalSourceLocation::UriReference {
uri: "file:///C:/CAD/xref-source.dwg".into(),
},
IfccadExternalSourceLocation::UriReference {
uri: "example:offline-xref".into(),
},
]
.into_iter()
.enumerate()
{
let mut definition = d.external_sources[0].clone();
definition.id = gallery.id_counters.allocate_external_source_id()?;
definition.name = [
"Relative",
"Search filename",
"Absolute file URI",
"Unresolved URI",
][index]
.into();
definition.location = location;
let mut entity = prototype.clone();
let IfccadEntity::Native(native) = &mut entity else {
unreachable!()
};
native.id = gallery.id_counters.allocate_entity_id()?;
native.layer_id = layers[&native.layer_id];
let IfccadEntityKind::Xref(xref) = &mut native.kind else {
unreachable!()
};
xref.source_id = definition.id;
xref.placement.origin[0] += index as f64 * 2000.;
gallery.external_sources.push(definition);
gallery.model.entities.push(entity);
}
validate_ifccad_document(&gallery)?;
let encoded = encode_ifccad_document(&gallery)?;
load_ifccad_bytes(encoded.bytes(), Default::default())?;
std::fs::write(public.join("xrefs.ifcx"), encoded.bytes())?;
}
let (native, mut context) = Ifcx.import_ifccad_preserving(&d)?;
assert!(native.losses.is_empty());
let back = Ifcx.export_ifccad_preserving(&native.document, &mut context)?;
assert_eq!(back.drawing.external_sources, d.external_sources);
std::fs::write(
drawings.join("hoofd.ifcx"),
encode_ifccad_document(&d)?.bytes(),
)?;
std::fs::write(
drawings.join("hoofd.ifccad.cbor"),
encode_ifccad_cbor_document(&d)?.bytes(),
)?;
for (name, format, guid) in [
("hoofd-retour.dwg", &Dwg as &dyn Format, true),
("hoofd-retour.dxf", &Dxf as &dyn Format, false),
] {
let (bytes, losses) = format.write(&native.document)?;
assert!(losses.is_empty());
let (read, _) = format.read(&bytes)?;
let back = Ifcx.export_ifccad(&read)?;
validate_ifccad_document(&back.drawing)?;
assert_eq!(back.drawing.external_sources.len(), 1);
let IfccadExternalSourceContent::Dwg {
fingerprint_guid, ..
} = &back.drawing.external_sources[0].source;
assert_eq!(fingerprint_guid.is_some(), guid);
std::fs::write(drawings.join(name), bytes)?;
}
println!("{}", root.display());
Ok(())
}
4 changes: 4 additions & 0 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ impl Format for Dwg {
}

fn write(&self, document: &Document) -> Result<(Vec<u8>, Vec<Loss>), Error> {
#[cfg(feature = "ifcx")]
crate::validate_cad_external_sources(document)?;
Ok((DwgWriter::write_to_vec(document)?, Vec::new()))
}
}
Expand All @@ -74,6 +76,8 @@ impl Format for Dxf {
}

fn write(&self, document: &Document) -> Result<(Vec<u8>, Vec<Loss>), Error> {
#[cfg(feature = "ifcx")]
crate::validate_cad_external_sources(document)?;
Ok((DxfWriter::new(document).write_to_vec()?, Vec::new()))
}
}
2 changes: 2 additions & 0 deletions src/ifcx/dimension_graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ fn canonical(
/// Resource-only conversion context: never clone the drawing's entity graph.
fn resources(d: &IfccadDocument) -> IfccadDocument {
IfccadDocument {
external_sources: Vec::new(),
table_styles: Vec::new(),
table_data_links: Vec::new(),
data_tables: Vec::new(),
Expand Down Expand Up @@ -319,6 +320,7 @@ fn resources(d: &IfccadDocument) -> IfccadDocument {
}
fn context<'a>(document: &'a Document, drawing: &IfccadDocument) -> Writer<'a> {
Writer {
external_sources: HashMap::new(),
#[cfg(feature = "mline-pilot")]
roundtrip: None,
table_data_links: HashMap::new(),
Expand Down
Loading
Loading