feat(anatomy): view.canvas op on the loaded sheet; drawings read once at load

This commit is contained in:
bchanot committed 2026-10-14 23:51:45 +02:00
1 parent 1ec9316a73
commit 842797b440
5 files changed
+168

No files matched your search

+29
View File
@@ -8,6 +8,7 @@ use serde::Deserialize;
use super::index::{IndexedDocument, NoMainView, SheetIndex};
use super::schema::AnatomicalSheetDocument;
use crate::anatomy::svg::{Element, read_svg};
use crate::domain::archive::SheetStatus;
use crate::domain::js::JsInt;
use crate::domain::report::{ReportMigrationMap, SheetRef};
@@ -49,6 +50,23 @@ pub struct LoadedSheet {
pub asset_hashes: HashMap<String, String>,
pub migration_map: ReportMigrationMap,
index: SheetIndex,
/// Each asset read once at load (R3): the sanitised tree, or why it cannot be drawn. A
/// rejection only affects the views on that asset; `assets` keeps the raw texts (the
/// snapshot archives them).
drawings: HashMap<String, Drawing>,
}
/// A sheet drawing ready to compose, or the closed reason it cannot be drawn: the reader's
/// rejection, or `removed …` when the allowlist would take something out of a product
/// drawing (refused, never repaired: LRN-055).
pub type Drawing = Result<Element, String>;
fn read_drawing(text: &str) -> Drawing {
match read_svg(text) {
Ok(read) if read.removed.is_empty() => Ok(read.root),
Ok(read) => Err(format!("removed {}", read.removed.join(", "))),
Err(rejection) => Err(rejection.reason().to_owned()),
}
}
/// Why a bundled sheet cannot be loaded.
@@ -78,6 +96,11 @@ impl LoadedSheet {
let document = AnatomicalSheetDocument::deserialize(&data.document)?;
let migration_map = ReportMigrationMap::deserialize(&data.migration_map)?;
let index = SheetIndex::build(&document)?;
let drawings = data
.assets
.iter()
.map(|(id, text)| (id.clone(), read_drawing(text)))
.collect();
let r = data.reference;
Ok(Self {
status: data.status,
@@ -93,6 +116,7 @@ impl LoadedSheet {
asset_hashes: data.asset_hashes,
migration_map,
index,
drawings,
})
}
@@ -103,4 +127,9 @@ impl LoadedSheet {
pub fn index(&self) -> &SheetIndex {
&self.index
}
/// The drawing of an asset; `None` when the bundle has no such asset.
pub fn drawing(&self, asset_id: &str) -> Option<&Drawing> {
self.drawings.get(asset_id)
}
}