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
4 changes: 2 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,7 +19,7 @@ acadrust = { git = "https://github.com/hakanaktt/acadrust.git", rev = "f1f7a8b46
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 = "785590abb669c38afb700b339d36cc8cc0c18161", optional = true }
ifccad = { git = "https://github.com/OpenAEC-Foundation/ifccad.git", rev = "207a5ad6f24f73e1e53d994d4c3ac52d1e616ab7", optional = true }
web-time = { version = "1", optional = true }

[dev-dependencies]
Expand Down Expand Up @@ -50,3 +50,7 @@ required-features = ["ifcx"]
[[example]]
name = "leaders_gallery"
required-features = ["ifcx"]

[[example]]
name = "xref_placement_review"
required-features = ["ifcx", "mline-pilot"]
37 changes: 23 additions & 14 deletions docs/ifcx-xrefs.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
# External sources and Model XREF attachments
# External sources and XREF placements

The development mapping pairs with IFCCAD profile 0.12.0 / CBOR 12. The core
The development mapping pairs with IFCCAD profile 0.13.0 / CBOR 13. 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.
Supported placements use the shared block transform: an orthonormal owner
frame, rotation in radians and finite nonzero signed XYZ effective scale.
Model, Paper layouts and local blocks may own XREFs. Scale includes insertion
unit conversion once. INSERT coordinates use CAD OCS; native O belongs to the
owner frame. Frame angle and explicit rotation combine once. Source base
points belong to the external source and are subtracted once by the host.
Source Model alone is loaded even for Paper owners. Unknown units stay absent.
A definition without an INSERT is retained. Loaded external bodies and their
dependent blocks are not emitted as authored native geometry.

Attach and Overlay can share one native source ID. CAD requires distinct block
records for the two relationship types; context retains their shared source ID
when saving native files. A standalone CAD roundtrip has distinct source IDs for
those definitions: path/GUID equality never silently merges authored identities.
FileDepList identity is emitted once per source, with a count across all owners.

The pure location helpers distinguish a direct URI-reference from a search
filename. Relative CAD paths map to escaped relative URI-references; drive
Expand Down Expand Up @@ -45,9 +54,9 @@ 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.
Arrays and INSERT attributes remain explicit conversion losses. Nesting and
cycles retain the existing host-owned graph behavior. Binding, packaging,
remote download and additional source formats are outside this slice. The core
stays independent of CAD runtimes; Document owns CAD conversion and the host
owns resolution and IO. This is an unpublished native13 draft with an explicit
local IFCCAD patch, pending native staging and final downstream pins.
71 changes: 71 additions & 0 deletions examples/xref_placement_review.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//! Compact slice-A review files, read back through production readers.
use opencaddocument::{ifccad::*, *};
#[path = "../tests/support/xref_placement.rs"]
mod support;
fn main() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
let root = std::path::PathBuf::from(
std::env::args_os()
.nth(1)
.ok_or("output directory required")?,
);
std::fs::create_dir_all(root.join("Refs"))?;
let mut drawing = support::mixed_owners();
drawing.external_sources[0].location = IfccadExternalSourceLocation::UriReference {
uri: "Refs/Detail.dwg".into(),
};
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.,
)))?;
source.add_entity(EntityType::Circle(entities::Circle::from_center_radius(
Vector3::new(11., 21., 0.),
0.5,
)))?;
let mut text = entities::Text::new();
text.value = "XREF".into();
text.insertion_point = Vector3::new(10., 22., 0.);
text.height = 0.5;
source.add_entity(EntityType::Text(text))?;
for (name, format) in [
("Detail.dwg", &Dwg as &dyn Format),
("Detail.dxf", &Dxf as &dyn Format),
] {
let (bytes, losses) = format.write(&source)?;
assert!(losses.is_empty(), "{losses:?}");
format.read(&bytes)?;
std::fs::write(root.join("Refs").join(name), bytes)?;
}
let native = Ifcx.export_ifccad(&source)?.drawing;
let json = encode_ifccad_document(&native)?;
load_ifccad_bytes(json.bytes(), Default::default())?;
std::fs::write(root.join("Refs/Detail.ifccad"), json.bytes())?;
for (name, binary) in [("Gallery.ifccad", false), ("Gallery.cbor", true)] {
let bytes = if binary {
encode_ifccad_cbor_document(&drawing)?.bytes().to_vec()
} else {
encode_ifccad_document(&drawing)?.bytes().to_vec()
};
if binary {
load_ifccad_cbor_bytes(&bytes, Default::default())?;
} else {
load_ifccad_bytes(&bytes, Default::default())?;
}
std::fs::write(root.join(name), bytes)?;
}
let imported = Ifcx.import_ifccad(&drawing)?;
for (name, format) in [
("Gallery.dwg", &Dwg as &dyn Format),
("Gallery.dxf", &Dxf as &dyn Format),
] {
let (bytes, losses) = format.write(&imported.document)?;
assert!(losses.is_empty(), "{losses:?}");
let (cad, _) = format.read(&bytes)?;
validate_ifccad_document(&Ifcx.export_ifccad(&cad)?.drawing)?;
std::fs::write(root.join(name), bytes)?;
}
println!("Review files: {}", root.display());
Ok(())
}
2 changes: 1 addition & 1 deletion examples/xref_review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn main() -> std::result::Result<(), Error> {
unreachable!()
};
xref.source_id = definition.id;
xref.placement.origin[0] += index as f64 * 2000.;
xref.transform.placement.origin[0] += index as f64 * 2000.;
gallery.external_sources.push(definition);
gallery.model.entities.push(entity);
}
Expand Down
8 changes: 4 additions & 4 deletions src/ifcx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const TEMPLATE: &str = r#"{
"author": "OpenCAD",
"timestamp": "1970-01-01T00:00:00Z"
},
"imports": [{ "uri": "urn:example:ifccad:0.12.0" }],
"imports": [{ "uri": "urn:example:ifccad:0.13.0" }],
"schemas": {},
"data": [
{
Expand All @@ -103,7 +103,7 @@ const TEMPLATE: &str = r#"{
"nextLayoutId": 2,
"nextLinePatternId": 1,
"nextSymbolSourceId": 1,
"profileVersion": "0.12.0",
"profileVersion": "0.13.0",
"nextUcsId": 1,
"nextModelWindowId": 1
}
Expand Down Expand Up @@ -749,7 +749,7 @@ fn add_in(
return Ok(None);
};
let converted = match &entity.kind {
IfccadEntityKind::Xref(source) => xref::insert_in(source, names),
IfccadEntityKind::Xref(source) => xref::insert_in(source, names, losses),
IfccadEntityKind::Dimension(source) => {
dimension::dimension_in(source, document, names, losses)
}
Expand Down Expand Up @@ -1497,7 +1497,7 @@ impl Losses {

fn entity_in(kind: &IfccadEntityKind, names: &Names, losses: &mut Losses) -> Option<EntityType> {
Some(match kind {
IfccadEntityKind::Xref(source) => return xref::insert_in(source, names),
IfccadEntityKind::Xref(source) => return xref::insert_in(source, names, losses),
IfccadEntityKind::AttributeDefinition(a) => {
return attributes::definition_in(a, names, losses)
}
Expand Down
Loading
Loading