diagram_core/src/structure.rs#
Source: lib/diagram_core/src/structure.rs
structure -- containers, lists and callouts (JD10: ST-01, ST-02, ST-04 .. ST-06)
kind(doc, shape) -> Option<Kind> Container, List or Callout (User.msvStructureType)
container(doc, c) -> Option<Container> its settings: margin, automatic size, lock, style,
heading, the categories it takes or refuses
list(doc, l) -> Option<List> a list's direction, spacing and alignment
members(doc, c) / containers_of(doc, s) / list_of(doc, s)
callouts_of(doc, t) / target_of(doc, callout)
categories(doc, s) / has_category(doc, s, name)
inner_box(doc, c) the box members live in (the heading taken off)
drop_targets(doc, owner, shapes) the containers a shape would join where it is now
carried(doc, shapes) the shapes plus what moves, copies and deletes with
them: members (nested too) and callouts
add_members / remove_members / set_target both sides of a relationship
settle(tx, eng, owner, shapes, membership) after a gesture: membership by position,
lists laid out, containers sized (deepest first)
fit(tx, eng, c, shrink) a container around its members (An Inhalt anpassen)
layout_list(tx, eng, l) / list_index_at / move_in_list / insert_marks
forget(tx, eng, deleted) before deleting: the survivors let go of them
disband(tx, eng, c) the container goes, its members stay
repair(tx, owner) relationships named on one side only are dropped
aim_callouts(tx, eng, callouts) a callout's tail back onto its target
edge::* (JD21, ST-03) boundary members: on a container's
edge (Relationships 7 .. 10), they go with the edge
The file keeps the structure in the Relationships cell of both shapes (structure::rel) and
the settings in User cells named as Visio names them (msvStructureType, msvSDContainer*,
msvSDList*, msvSDHeadingStyle, msvShapeCategories), so Visio recognises what JFDiagrammer
writes and the other way round. What a container looks like is the master's (own
stencils in apps/JFDiagrammer/stencils): the code knows only the cells.
The heading: Visio's own containers are groups whose subshape with msvStructureType
"Heading" carries msvSDContainerHeadingEdge -- the side where the inside lies, seen from the
heading ("Bottom" for a heading on top); JFDiagrammer's containers are one shape with the
heading drawn in it and User.JFD_HeadingEdge (the edge the heading is on: Top, Bottom, Left,
Right, None) and User.JFD_HeadingSize on the container itself. Both are read; the inner box
is the frame without the heading.
Rules (Visio's, as far as they are documented, else chosen and named here):
* A 2D shape joins every container whose frame holds its whole box after a drop or move and
that takes it, nested ones too (Visio stores membership in each enclosing container: a
process shape is in its lane, its phase and the lanes' list); a list takes it as an item
when the list's box holds its middle and the list's item categories let it, at the index
its place gives. 1D shapes, guides, callouts and headings never join by position.
* It leaves a container when it lies wholly outside it, or when it found new containers and
lies not wholly in this one; partly outside it stays and the container grows (automatic
size "expand"). A locked container (msvSDContainerLocked) neither takes nor lets go.
* Required categories: one of them must be among the shape's (msvShapeCategories, ';'
separated, case-insensitive; a shape without categories is refused); excluded ones refuse.
* Only a list's items are laid out and size the list (Visio's); its plain members are not.
* Moving a container moves its members (nested ones too) and the callouts of everything
moved; deleting and copying take them along (carried).
* Nothing is computed when a file opens: settle runs only after a gesture.
* (JD21, ST-03) A shape dropped across an edge of a container sits on that edge (structure::edge):
a member that follows the edge, which the container's automatic size leaves out.
enum Kindwhat a shape is in a structured diagramContainer-- a container: members inside its frameList-- a list: a container with ordered members side by sideCallout-- a callout: a note tied to a target shape
enum Resizehow a container follows its members (msvSDContainerResize)None-- 0: never by itselfExpand-- 1: grows when members need room (Visio's default)Fit-- 2: always fits its members, grows and shrinks
enum Edgethe edge a container's heading is onNoneTopBottomLeftRight
impl Edge
fn parse(s: &str) -> Edgethe edge of a cell's text ("Top", "Bottom", "Left", "Right"; else none)fn opposite(self) -> Edgethe edge across from this onefn as_str(self) -> &'static strthe text Visio writesstruct Containera container's settingsmargin: f64-- msvSDContainerMargin: between the members and the inner box (drawing units, inches)resize: Resizelocked: bool-- msvSDContainerLocked: membership stays as it isno_highlight: bool-- msvSDContainerNoHighlight: no glow while a shape is dragged over itstyle: u32-- msvSDContainerStyle / msvSDHeadingStyle (1-based) and how many there arestyle_count: u32heading_style: u32heading_style_count: u32required: Vec<String>-- msvSDContainerRequiredCategories / msvSDContainerExcludedCategoriesexcluded: Vec<String>heading: Edge-- where the heading is and how deep it is (drawing units)heading_size: f64
enum Directiona list's order on the pageLeftToRight-- 0: left to rightRightToLeft-- 1: right to leftTopToBottom-- 2: top to bottomBottomToTop-- 3: bottom to top
impl Direction
fn from_code(v: i64) -> Directionfn code(self) -> i64fn horizontal(self) -> boolwhether the members stand side by side (else one above the other)struct Lista list's settings (msvSDListDirection, msvSDListSpacing, msvSDListAlignment)direction: Directionspacing: f64-- between two members (drawing units)align: u8-- across the direction: 0 start (left / top), 1 middle, 2 end (right / bottom)stretch: bool-- User.JFD_ListStretch (JFDiagrammer's own, for lanes): every item as long across as the list's inner box or the longest item
fn user_text(doc: &Document, s: ShapeRef, name: &str) -> Option<String>a User cell's value as text (a number as Visio shows it)fn user_num(doc: &Document, s: ShapeRef, name: &str) -> Option<f64>a User cell's value as a numberfn kind(doc: &Document, s: ShapeRef) -> Option<Kind>what a shape is in a structured diagram (None: an ordinary shape, also a heading)fn is_container(doc: &Document, s: ShapeRef) -> boolwhether the shape takes members (a container or a list)fn categories(doc: &Document, s: ShapeRef) -> Vec<String>the categories of a shape (msvShapeCategories, ';' separated)fn has_category(doc: &Document, s: ShapeRef, name: &str) -> boolwhether the shape has a category (case-insensitive)fn container(doc: &Document, c: ShapeRef) -> Option<Container>a container's settings (None: not a container or list)fn list(doc: &Document, l: ShapeRef) -> Option<List>a list's settings (None: not a list)fn master_name(t: &str) -> String(JD29) the master a list names:USE("Member")(Visio's form) orMember-> Memberfn item_master(doc: &Document, l: ShapeRef) -> Option<String>(JD29) the NameU of a list's item master (msvSDListItemMaster): what an insert mark adds
/// (JD29) the most starting items a list may name
MAX_START_ITEMS: usize = 32
fn start_items(doc: &Document, l: ShapeRef) -> Vec<String>(JD29) a list's starting items, Visio's: the masters msvSDListItemMaster1, 2, 3 ... name, in order (Visio's class names Member, Separator, Member; its database entity a key, the key separator and two attributes); Visio drops an instance of each with the listfn add_start_items(tx: &mut Transaction, eng: &mut Engine, l: ShapeRef, src: &Document, lang: usize) -> Result<Vec<ShapeRef>, EditError>(JD29) a list just dropped from stencilsrc: an instance of each of its starting items (masters ofsrcby NameU, names in languagelang) as its items in that order, the list laid out -> the new items. A list that has items already, or that names a mastersrclacks, gets none of them.fn place_item(tx: &mut Transaction, eng: &mut Engine, page: crate::document::PageRef, m: crate::document::MasterRef, at: [f64; 2], lang: usize) -> Result<ShapeRef, EditError>(JD29) an instance of mastermof the document at page pointat, computed (an item about to join a list)fn members(doc: &Document, c: ShapeRef) -> Vec<ShapeRef>every member of a container: a list's items in list order first, then its other membersfn items(doc: &Document, l: ShapeRef) -> Vec<ShapeRef>the items of a list in list order (the members it arranges)fn containers_of(doc: &Document, s: ShapeRef) -> Vec<ShapeRef>the containers and lists a shape is a member or an item offn list_of(doc: &Document, s: ShapeRef) -> Option<ShapeRef>the list a shape is an item offn callouts_of(doc: &Document, t: ShapeRef) -> Vec<ShapeRef>the callouts tied to a shapefn target_of(doc: &Document, callout: ShapeRef) -> Option<ShapeRef>the target of a calloutfn add_members(tx: &mut Transaction, eng: &mut Engine, c: ShapeRef, shapes: &[ShapeRef], at: Option<usize>) -> Result<(), EditError>make shapes members of a container (at: the position in a list, else at the end); a shape already in it stays where it isfn remove_members(tx: &mut Transaction, eng: &mut Engine, c: ShapeRef, shapes: &[ShapeRef]) -> Result<(), EditError>take shapes out of a containerfn set_target(tx: &mut Transaction, eng: &mut Engine, callout: ShapeRef, target: Option<ShapeRef>) -> Result<(), EditError>tie a callout to a target (None: let go of it)fn recalc(tx: &mut Transaction, eng: &mut Engine, shapes: &[ShapeRef]) -> Result<(), EditError>recompute what reads the Relationships cells of these shapes (the structure functions)fn shape_box(doc: &Document, s: ShapeRef) -> [f64; 4]a shape's upright box on the pagefn inner_box(doc: &Document, c: ShapeRef) -> [f64; 4]the box members live in: the frame without the heading (page, upright)fn joins_by_position(doc: &Document, s: ShapeRef) -> boolwhether a shape may join containers by its position: 2D, no guide, no callout, no heading, not a connectorfn accepts(doc: &Document, c: ShapeRef, s: ShapeRef) -> boolwhether containerctakes shapes(categories; never itself or one that holds it)fn accepts_item(doc: &Document, l: ShapeRef, s: ShapeRef) -> boolwhether listltakes shapesas an item (msvSDListRequiredCategories, msvSDListExcludedCategories); else it may still take it as a plain memberfn within(doc: &Document, inner: ShapeRef, outer: ShapeRef) -> boolwhetherinneris (transitively) a member ofouterfn drop_targets(doc: &Document, owner: Owner, s: ShapeRef, moving: &[ShapeRef]) -> Vec<ShapeRef>the containers onownera shape joins where it lies now, leaving outmoving(what moves with it): every container that holds its whole box and takes it (Visio keeps membership in each enclosing container, nested ones too: a process shape is in its lane, its phase and the lanes' list), and a list whose box holds its middle and that takes it as an itemfn carried(doc: &Document, shapes: &[ShapeRef]) -> Vec<ShapeRef>the shapes plus everything that moves, copies and is deleted with them: members of containers (nested too) and callouts of every shape in it; the shapes come firstfn needed_box(doc: &Document, c: ShapeRef) -> Option<[f64; 4]>the box a container needs for its members (a list: its items only, they alone size it): their box, the margin around it, the headingfn fit(tx: &mut Transaction, eng: &mut Engine, c: ShapeRef, shrink: bool) -> Result<bool, EditError>fit a container around its members: grow only (shrinkfalse) or exactly; an empty or turned container stays -> whether it changedfn layout_list(tx: &mut Transaction, eng: &mut Engine, l: ShapeRef) -> Result<Vec<ShapeRef>, EditError>the items of a list in list order laid out side by side from the start of its inner box (margin, spacing, alignment across), then the list fitted around them -> the shapes movedfn list_index_at(doc: &Document, l: ShapeRef, p: [f64; 2], leave_out: &[ShapeRef]) -> usizewhere a shape at page pointpgoes in a list: the index of the first member whose middle lies beyond p along the list's directionstruct Marka mark between two members of a list (the insert triangle, the insertion bar while a shape is dragged in): its page point, the direction the list runs, the index a shape inserted there getsat: [f64; 2]to: [f64; 2]-- the far end of the insertion bar across the listdirection: Directionindex: usize
fn insert_marks(doc: &Document, l: ShapeRef) -> Vec<Mark>the marks of a list: before the first member, between members, after the lastfn insert_marks_without(doc: &Document, l: ShapeRef, leave_out: &[ShapeRef]) -> Vec<Mark>the marks of a list as ifleave_out(an item being dragged) were not in itfn move_in_list(tx: &mut Transaction, eng: &mut Engine, l: ShapeRef, s: ShapeRef, index: usize) -> Result<Vec<ShapeRef>, EditError>put a member of a list at another index and lay the list outfn settle(tx: &mut Transaction, eng: &mut Engine, owner: Owner, shapes: &[ShapeRef], membership: bool) -> Result<Vec<ShapeRef>, EditError>aftershapeswere dropped, moved, resized or turned (what they carried moved with them): withmembershipthe containers they join and leave by their new place (a list: at the index their place gives); then every container concerned, the deepest first: lists laid out, containers sized by their automatic size -> every shape that moved here (for the glue to follow)fn forget(tx: &mut Transaction, eng: &mut Engine, deleted: &[ShapeRef]) -> Result<Vec<ShapeRef>, EditError>beforedeletedgo: the shapes that stay let go of them; lists close the gap -> the shapes that moved (lists laid out)fn disband(tx: &mut Transaction, eng: &mut Engine, c: ShapeRef) -> Result<(), EditError>the container goes, its members stay (they leave it; a nested container's members stay in it); the container's own containers lose itfn repair(tx: &mut Transaction, eng: &mut Engine, owner: Owner, shapes: &[ShapeRef]) -> Result<(), EditError>relationships named on one side only (after a paste or a foreign edit) are dropped;shapeslimits the check (empty: every shape of the owner)fn anchor(doc: &Document, callout: ShapeRef) -> [f64; 2]the anchor of a callout on its target: fractions of the target's box (User.JFD_TargetX, User.JFD_TargetY; the middle when missing)fn target_point(doc: &Document, callout: ShapeRef) -> Option<[f64; 2]>the page point a callout points at: the anchor on its targetfn set_anchor(tx: &mut Transaction, callout: ShapeRef, p: [f64; 2]) -> Result<(), EditError>remember where on its target a callout points (the page pointp)fn association(doc: &Document, callout: ShapeRef) -> Option<ops::Control>the control row a callout is tied by: Controls.Association (Visio requires it for callouts), else the first control pointfn aim_callouts(tx: &mut Transaction, eng: &mut Engine, callouts: &[ShapeRef]) -> Result<(), EditError>the tail of callouts back onto their target: the association point (the tip of the tail) goes to the anchor on the targetfn set_user_length(tx: &mut Transaction, s: ShapeRef, name: &str, inches: f64, unit: Unit) -> Result<(), EditError>a length cell of a User row as Visio writes it: inches with a unit to showfn user_addr(doc: &Document, name: &str) -> Option<CellAddr>a User cell's address (for the formula engine's dependencies)