Skip to main content

dotloom_io/
lib.rs

1//! # dotloom-io
2//!
3//! File formats for Dotloom:
4//!
5//! * `.dotl` project files (ZIP container with `manifest.json`, `document.json`,
6//!   optional `view.json` and content-addressed `assets/`), read with a bounded
7//!   parser and written atomically on native platforms;
8//! * SVG and ASCII DXF import/export with explicit [`ConversionReport`]s listing
9//!   what each format cannot carry.
10//!
11//! PNG export lives in `dotloom-render` (it needs a GPU adapter).
12
13pub mod dotl;
14pub mod dxf;
15mod report;
16pub mod svg;
17pub mod zip;
18
19use dotloom_engine::{
20    ApplyOptions, Command, CommitReport, Engine, EngineError, NewEntity, Transaction,
21    document::{Color, LayerId},
22};
23
24pub use dotl::{DotlError, DotlFile, DotlLimits, LoadReport, Manifest, read_dotl, write_dotl};
25pub use report::{ConversionReport, Loss, LossKind};
26
27/// Add imported layers and entities to an engine in one transaction (one undo step).
28pub fn import_into(
29    engine: &mut Engine,
30    label: &str,
31    layers: &[(String, Option<Color>)],
32    entities: Vec<(usize, NewEntity)>,
33) -> Result<CommitReport, EngineError> {
34    let ids = engine.reserve_ids(layers.len());
35    let mut commands = Vec::with_capacity(layers.len() + entities.len());
36    let mut layer_ids = Vec::with_capacity(layers.len());
37    for ((name, color), id) in layers.iter().zip(ids) {
38        let lid = LayerId(id);
39        layer_ids.push(lid);
40        commands.push(Command::AddLayer { id: Some(lid), name: name.clone() });
41        if let Some(c) = color {
42            commands.push(Command::UpdateLayer {
43                id: lid,
44                patch: dotloom_engine::LayerPatch { color: Some(*c), ..Default::default() },
45            });
46        }
47    }
48    for (li, mut e) in entities {
49        e.layer = layer_ids.get(li).copied();
50        commands.push(Command::CreateEntity { id: None, entity: e });
51    }
52    engine.apply(Transaction::new(label, commands), ApplyOptions::default())
53}