diagram_core/src/document.rs#
Source: lib/diagram_core/src/document.rs
document -- the document: pages, masters, styles, the document sheet, themes and parts
Document::new(DocKind::Drawing) empty: no pages, masters or styles
doc.intern("PinX") / sym(..) / str(sym) the document's string table (strings.rs)
doc.pages() / page(r) / page_by_id(id) / page_by_name_u(..) (masters, styles alike)
doc.shape(r) -> Option<Shape> a shape with its links: id, data, children,
parent, master shape, NameU and Name
doc.sheet(SheetRef) / sheet_styles(..) any ShapeSheet of the document
doc.insert_page(page) / insert_master / insert_style (untracked, for loaders)
doc.page_mut(r) / master_mut / style_mut / doc_sheet_mut (untracked)
doc.unused_page_name("Page") "Page-3": the first free number
doc.transaction(label) tracked edits with undo (edit.rs)
Handles: PageRef, MasterRef and StyleRef are slots of the document like ShapeRef is a slot of
its tree: stable for the document's life, also across undo, never reused. The file's IDs
(page ID, master ID, style ID, shape ID) are attributes of the objects; references inside
the model use them as the file does (Master="2", LineStyle="3", BackPage="4", MasterShape),
so a shape whose master is gone still says which one it was.
Untracked access (the *_mut functions, the public fields) is for building a document --
diagram_io while reading, tests -- and for data the edit API does not cover yet. Changes
made that way bypass the transactions, so an undo history recorded before them no longer
fits the document: clear it.
Names (LG-04): NameU is the universal key (formulas, matching masters, own shapes), Name what
the user sees; a file's Name stays as read. A shape without NameU is "Sheet.<ID>", an
instance "<master's NameU>.<ID>"; without Name it shows its NameU.
struct PageRef(pub(crate) u32)a page of the document (a slot, stable across undo)struct MasterRef(pub(crate) u32)a master of the documentstruct StyleRef(pub(crate) u32)a style of the documentenum Ownerwhat holds a shape treePage(PageRef)-- the shapes of a pageMaster(MasterRef)-- the shapes of a master
struct ShapeRefa shape: its tree and its slot thereowner: Owner-- the page or masterslot: u32-- the slot in its tree
enum SheetRefany ShapeSheet of the documentDocument-- the document sheetStyle(StyleRef)-- a style sheetPage(PageRef)-- a page sheetMaster(MasterRef)-- a master's page sheetShape(ShapeRef)-- a shape's sheet
enum DocKindwhat the document isDrawing-- a drawing (.vsdx, .vsdm)Template-- a template (.vstx, .vstm)Stencil-- a stencil: masters without pages (.vssx, .vssm)
struct DocSettingsthe DocumentSettings elementtop_page: Option<u32>-- TopPage: the ID of the page shown firstdefault_text_style: Option<u32>-- DefaultTextStyle: the style ID new text getsdefault_line_style: Option<u32>-- DefaultLineStyledefault_fill_style: Option<u32>-- DefaultFillStyledefault_guide_style: Option<u32>-- DefaultGuideStyleattrs: Vec<(Sym, Sym)>-- the other attributes in file orderitems: Vec<(Sym, Sym)>-- the child elements and their text in file order (GlueSettings, SnapSettings, SnapExtensions, SnapAngles, DynamicGridEnabled, ProtectStyles ...)extras: Extras-- unknown items
struct ColorEntryan entry of the old colour table (Colors): index -> RGBix: u32-- IXrgb: Sym-- RGB as written ("#000000")
struct FaceNamea font of the document (FaceName), its attributes in file order (NameU, Panose ...)attrs: Vec<(Sym, Sym)>-- the attributes
struct DocSheetthe document's own ShapeSheet (DocumentSheet)styles: StyleRefs-- LineStyle, FillStyle, TextStyleattrs: Vec<(Sym, Sym)>-- the other attributes in file order (Name, NameU ...)sheet: Sheet-- the cells
struct Themea theme part, kept as read (typed later, JD11)part: Sym-- the part name (/visio/theme/theme1.xml)data: Vec<u8>-- its bytes
struct Parta package part the model keeps as bytes: media, document properties, windows, comments, the thumbnail, a macro project (data recordsets are Document::data since JD18)name: Sym-- the part namecontent_type: Sym-- its content typerel_type: Sym-- the type of the relationship that points to itdata: Vec<u8>-- its bytes
struct Relationshipa relationship of the package as read: which part (or the package) points to which target with which type. The model derives the ones it owns (pages, masters, themes, pictures) from its own links when it writes; the list keeps every relationship so that parts it only keeps as bytes (Part), external targets and ids that kept XML refers to (r:id) survivesource: Sym-- the source part (/visio/document.xml), "" for the package itselfid: Sym-- the id (rId3), unique per sourcekind: Sym-- the type, a URItarget: Sym-- the target as written: relative to the source, or a URI when externalexternal: bool-- TargetMode="External": outside the package, never followedpart: Option<Sym>-- the part an internal target names (/visio/media/image1.png); None when external
enum DocErrorwhy an object could not be put into the documentDuplicateId(u32)-- another object of the same kind has this ID
struct Documenta drawing, template or stencilkind: DocKind-- drawing, template or stencilmacros: bool-- whether the file is macro-enabled (.vsdm, .vssm, .vstm); macros are kept, never runsettings: DocSettings-- DocumentSettingscolors: Vec<ColorEntry>-- the old colour tablefaces: Vec<FaceName>-- the fontsthemes: Vec<Theme>-- the theme parts (Page::theme indexes them)parts: Vec<Part>-- the other package parts, as bytesdata: crate::data::DataSets-- (JD18) external data: connections, recordsets, rows bound to shapes (data.rs; changed through data::* in transactions)rels: Vec<Relationship>-- every relationship of the package as read (see Relationship)attrs: Vec<(Sym, Sym)>-- the attributes of the VisioDocument elementextras: Extras-- unknown items of the VisioDocument element (EventList, HeaderFooter, PublishSettings ... until they are typed)pages_extras: Extras-- unknown items of the Pages elementmasters_extras: Extras-- unknown items of the Masters elementcolors_extras: Extras-- unknown items of the Colors element (a ColorEntry with more than IX and RGB too)faces_extras: Extras-- unknown items of the FaceNames element (a FaceName with children too)styles_extras: Extras-- unknown items of the StyleSheets elementfields: crate::field::Env-- what text fields show that the file does not hold: the app's locale and clock, the file's path (field::Env; never written)
impl Document
fn new(kind: DocKind) -> Documentan empty document of this kindfn strings(&self) -> &Stringsthe string tablefn strings_mut(&mut self) -> &mut Stringsthe string table to add to (loaders hand it to Value::parse, Formula::parse, ShapeKind::parse); it only grows, so every Sym stays validfn intern(&mut self, text: &str) -> Symthe handle of a text, added when newfn sym(&self, text: &str) -> Option<Sym>the handle of a text the document already hasfn str(&self, sym: Sym) -> &strthe text of a handlefn pages(&self) -> impl Iterator<Item = PageRef> + '_the pages in document order (foreground and background)fn foreground_pages(&self) -> impl Iterator<Item = PageRef> + '_the foreground pages in document orderfn background_pages(&self) -> impl Iterator<Item = PageRef> + '_the background pages in document orderfn page_count(&self) -> usizethe number of pagesfn page(&self, r: PageRef) -> Option<&Page>a pagefn page_mut(&mut self, r: PageRef) -> Option<&mut Page>a page for untracked changes (see the module comment)fn page_by_id(&self, id: u32) -> Option<PageRef>the page with this page IDfn page_by_name_u(&self, name_u: &str) -> Option<PageRef>the page with this universal namefn page_position(&self, r: PageRef) -> Option<usize>the position of a page in document orderfn background_of(&self, r: PageRef) -> Option<PageRef>the background page of a pagefn insert_page(&mut self, page: Page) -> Result<PageRef, DocError>add a page at the end (untracked)fn unused_page_name(&self, prefix: &str) -> String"<prefix>-<n>" with the smallest n no page has as Name or NameUfn masters(&self) -> impl Iterator<Item = MasterRef> + '_the masters in document orderfn master(&self, r: MasterRef) -> Option<&Master>a masterfn master_mut(&mut self, r: MasterRef) -> Option<&mut Master>a master for untracked changesfn master_by_id(&self, id: u32) -> Option<MasterRef>the master with this master IDfn master_by_name_u(&self, name_u: &str) -> Option<MasterRef>the master with this universal namefn insert_master(&mut self, master: Master) -> Result<MasterRef, DocError>add a master at the end (untracked)fn styles(&self) -> impl Iterator<Item = StyleRef> + '_the styles in document orderfn style(&self, r: StyleRef) -> Option<&Style>a stylefn style_mut(&mut self, r: StyleRef) -> Option<&mut Style>a style for untracked changesfn style_by_id(&self, id: u32) -> Option<StyleRef>the style with this style IDfn style_by_name_u(&self, name_u: &str) -> Option<StyleRef>the style with this universal namefn insert_style(&mut self, style: Style) -> Result<StyleRef, DocError>add a style at the end (untracked)fn doc_sheet(&self) -> &DocSheetthe document's own ShapeSheetfn doc_sheet_mut(&mut self) -> &mut DocSheetthe document sheet for untracked changesfn sheet(&self, r: SheetRef) -> Option<&Sheet>any sheet of the documentfn sheet_styles(&self, r: SheetRef) -> StyleRefsthe styles a sheet inherits from (a style: the styles it is based on)fn tree(&self, owner: Owner) -> Option<&ShapeTree>the shape tree of a page or masterfn shape(&self, r: ShapeRef) -> Option<Shape<'_>>a shape and its linksfn shape_by_id(&self, owner: Owner, id: u32) -> Option<ShapeRef>the shape with this file ID on a page or in a masterfn top_shapes(&self, owner: Owner) -> impl Iterator<Item = ShapeRef> + '_the top-level shapes of a page or master in z-orderfn all_shapes(&self, owner: Owner) -> impl Iterator<Item = ShapeRef> + '_every shape of a page or master, groups before their subshapesfn master_shape_of(&self, r: ShapeRef) -> Option<ShapeRef>the shaperinherits from: for an instance its master's master shape, for a subshape of an instance the shape MasterShape names in the instance's masterfn master_of(&self, r: ShapeRef) -> Option<MasterRef>the master an instance (or a subshape of one) belongs tofn master_in_use(&self, id: u32) -> boolwhether any shape of the document is an instance of the master with this IDfn master_depends_on(&self, a: u32, b: u32) -> boolwhether the master with IDauses the master with IDb(itself or through instances in its shapes, at any depth)fn style_in_use(&self, id: u32) -> boolwhether any sheet, style or setting of the document names the style with this IDstruct Shape<'d>a shape with access to its document (Document::shape)
impl<'d> Shape<'d>
fn r(&self) -> ShapeRefits handlefn id(&self) -> u32its file ID (unique on its page or in its master)fn data(&self) -> &'d ShapeDataeverything it holds itselffn header(&self) -> &'d ShapeHeaderits attributesfn sheet(&self) -> &'d Sheetits own cells (without inheritance)fn sheet_ref(&self) -> SheetRefas a sheet referencefn parent(&self) -> Option<ShapeRef>the group it belongs tofn children(&self) -> impl Iterator<Item = ShapeRef> + 'dits subshapes in z-orderfn master_shape(&self) -> Option<ShapeRef>the shape it inherits from (Document::master_shape_of)fn is_deleted(&self) -> boolwhether the master's subshape is deleted here (Del="1")fn text(&self) -> Option<&'d Text>its text, from the master shape when it has none of its ownfn name_u(&self) -> Stringthe universal name: NameU, else derived ("Sheet.7", "<master's NameU>.7")fn name(&self) -> Stringthe shown name: Name, else NameU, else derived from the master's Name