diagram_core/src/instance.rs#
Source: lib/diagram_core/src/instance.rs
instance -- masters from stencils onto pages (JD9): a master taken into a document, an
instance of it dropped on a page, the texts of masters and stencils in five languages
LANGS, lang_index("fr") de en es it fr: the order of every five-language value
join_fields(&[..]) / split_fields(text) the '|'-separated values of a JFD_ cell
("\|" and "\\" escape)
MasterTexts::of(&doc, master) names, QuickInfos, keywords, text and translated cells in
five languages, the quick flag (JFD_ cells of the master's
page sheet; a master without them: Name, Prompt and
ShapeKeywords for every language)
texts.name(lang) / matches(&words, any) the name shown, the search (NameU, the names in
all five languages, the keywords, since JD15 the
QuickInfos)
StencilTexts::of(&doc) a stencil's title in five languages and its category
(User.JFD_Name, User.JFD_Category of the document sheet)
import_master(&mut tx, &src, m) -> MasterRef master m of document src in tx's document:
the copy already there with the same UniqueID (MS-02),
else a new copy: strings into this document's table,
styles matched by NameU (missing ones copied with their
bases), masters its shapes are instances of first,
pictures of package parts inline
move_master(&mut tx, m, pos) a master to another place in the order (own stencils)
scale_factor(&doc, page, master) (JD15, MS-10) Visio's range of eight: 1 while the
master's drawing scale is within eight times the page's,
else the factor that keeps its size on the paper
place(&mut tx, page, master, x, y, lang) -> ShapeRef an instance at (x, y) inches on the
page (y up), (JD15, MS-10) its constant lengths (Shape and
Text Transform, User / Prop values with a unit of length,
X and Y of Geometry, Connection, Control rows; a 1-D
shape's ends around the pin) times scale_factor when that
is not 1: Name in language lang, NameU the master's
(LG-04; "Rechteck.7" when the page has one already), its
text and translated cells in that language; (JD8 rest,
LY-03) the master's layers come along: the page gets the
ones it lacks (matched by NameUniv, else Name, with the
master's Visible, Print, Lock, Snap, Glue, Color and
ColorTrans) and every shape of the instance its own
LayerMember with the page's indices (the master's name
the rows of its own Layer section)
detach(&mut tx, shape) (JD21, SP-06) an instance made plain shapes: what it
inherits from its master shapes becomes its own, the link
to the master goes (before it is ungrouped; detach.rs)
The JFD_ cells are JFDiagrammer's own (apps/JFDiagrammer/stencils/README.md); diagram_io's
stencil builder writes them, the Shapes panel reads them. Visio keeps them as ordinary User
cells. The caller recalculates after place (formula::Engine::recalc with the new shapes'
sheets) inside the same transaction, so undo takes the drop back as one step.
/// the five languages, in the order of every five-language value
LANGS: [&str; 5] = ["de", "en", "es", "it", "fr"]
/// User cells of a stencil's document sheet and of a master's page sheet (README of the stencils)
JFD_NAME: &str = "JFD_Name"
/// the QuickInfos of a master
JFD_PROMPT: &str = "JFD_Prompt"
/// the search words of a master, per language separated by commas
JFD_KEYWORDS: &str = "JFD_Keywords"
/// the text a master's instance carries
JFD_TEXT: &str = "JFD_Text"
/// 1: the master is a quick shape of its stencil (MS-04)
JFD_QUICK: &str = "JFD_Quick"
/// the category of a stencil in "Weitere Shapes"
JFD_CATEGORY: &str = "JFD_Category"
/// JFD_Tr1, JFD_Tr2 ...: "Section.Row.Cell|de|en|es|it|fr" for translated cells of the master shape
JFD_TR: &str = "JFD_Tr"
fn lang_index(code: &str) -> Option<usize>the position of a language code in LANGSfn join_fields(values: &[&str]) -> Stringvalues joined with '|' ('|' and '\' escaped with '\')fn split_fields(text: &str) -> Vec<String>the values of a '|'-joined textstruct MasterTextsthe texts of a master in five languagesname_u: String-- NameU: the key (LG-04)names: [String; 5]-- the names shown, by LANGSprompts: [String; 5]-- the QuickInfoskeywords: [String; 5]-- the search words, comma separatedtext: Option<[String; 5]>-- the text an instance carriestranslated: Vec<(String, [String; 5])>-- translated cells of the master shape: "Section.Row.Cell" and its five textsquick: bool-- a quick shape of its stencil (MS-04)
impl MasterTexts
fn of(doc: &Document, m: MasterRef) -> MasterTextsthe texts of masterm(empty for a master that is not there)fn name(&self, lang: usize) -> &strthe name in languagelang(index into LANGS), else the first one there, else NameUfn prompt(&self, lang: usize) -> &strthe QuickInfo in languagelangfn matches(&self, words: &[&str], any: bool) -> boolwhether the master matches the search words (lower case expected): all of them (any = false) or one of them, each a part of NameU, of a name in any language, of a keyword or (JD15) of a QuickInfo in any language (SL-04: Visio searches the description)fn fold(s: &str) -> Stringa text in lower case without the accents of the five languages (search ignores both)struct StencilTextsthe texts of a stencilnames: [String; 5]-- the title in five languages (empty: the stencil has none; the app takes its file name)category: String-- the category in "Weitere Shapes" ("" when none)
impl StencilTexts
fn of(doc: &Document) -> StencilTextsthe texts of the stencildocfn name(&self, lang: usize) -> &strthe title in languagelang, else the first one there ("" when none)fn import_master(tx: &mut Transaction, src: &Document, m: MasterRef) -> Result<MasterRef, EditError>mastermof documentsrcin the document oftx: the copy already there with the same UniqueID, else a new copy (see the head of this file)fn place(tx: &mut Transaction, page: PageRef, master: MasterRef, x: f64, y: f64, lang: usize) -> Result<ShapeRef, EditError>drop an instance ofmasterat (x, y) inches onpage(MS-02, LG-04): Name in languagelang(an index into LANGS), NameU the master's, unique on the page with ".ID" like Visio; the text and translated cells in that language where they differ from the master'sfn localize_parts(tx: &mut Transaction, shape: ShapeRef, lang: usize) -> Result<Vec<ShapeRef>, EditError>(JD26) the subshapes of instanceshapein languagelang(an index into LANGS): a subshape whose master subshape has User.JFD_Text (its text in five languages: the parts of a group master, stencils/README.md) gets the text oflangwhere it shows one of the five or none -> the subshapes whose text changedfn scale_factor(doc: &Document, page: PageRef, master: MasterRef) -> f64(JD15, MS-10) Visio's range of eight (User's Guide, chapter 18: "Visio adjusts an instance of a master automatically if its drawing scale is more than eight times larger or smaller than the drawing scale of the page. If the scales differ less, Visio doesn't adjust the shape"): 1 within the range, else the factor that keeps the instance's size on the paper -- the master's page units per drawing unit (PageScale / DrawingScale of its page sheet) over the page'sfn bring_layers(tx: &mut Transaction, page: PageRef, master: MasterRef, shape: ShapeRef) -> Result<(), EditError>(LY-03) the layers ofmasterthat the shapes of its instanceshapeare on: the page gets the ones it lacks (matched by NameUniv, else Name), each shape of the instance its own LayerMember with the page's indices (Visio's: a master's shapes name the rows of the master's Layer section, an instance on a page names the page's)fn base64(data: &[u8]) -> Stringbase64 (RFC 4648, with padding)fn move_master(tx: &mut Transaction, m: MasterRef, pos: usize) -> Result<(), EditError>move mastermto positionposamong the masters (a stencil's order: MS-04, SL-07); a master in use by shapes of the document stays where it is (InUse)