JFLib

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 Kind what a shape is in a structured diagram

    • Container -- a container: members inside its frame
    • List -- a list: a container with ordered members side by side
    • Callout -- a callout: a note tied to a target shape
  • enum Resize how a container follows its members (msvSDContainerResize)

    • None -- 0: never by itself
    • Expand -- 1: grows when members need room (Visio's default)
    • Fit -- 2: always fits its members, grows and shrinks
  • enum Edge the edge a container's heading is on

    • None
    • Top
    • Bottom
    • Left
    • Right

impl Edge

  • fn parse(s: &str) -> Edge the edge of a cell's text ("Top", "Bottom", "Left", "Right"; else none)

  • fn opposite(self) -> Edge the edge across from this one

  • fn as_str(self) -> &'static str the text Visio writes

  • struct Container a container's settings

    • margin: f64 -- msvSDContainerMargin: between the members and the inner box (drawing units, inches)
    • resize: Resize
    • locked: bool -- msvSDContainerLocked: membership stays as it is
    • no_highlight: bool -- msvSDContainerNoHighlight: no glow while a shape is dragged over it
    • style: u32 -- msvSDContainerStyle / msvSDHeadingStyle (1-based) and how many there are
    • style_count: u32
    • heading_style: u32
    • heading_style_count: u32
    • required: Vec<String> -- msvSDContainerRequiredCategories / msvSDContainerExcludedCategories
    • excluded: Vec<String>
    • heading: Edge -- where the heading is and how deep it is (drawing units)
    • heading_size: f64
  • enum Direction a list's order on the page

    • LeftToRight -- 0: left to right
    • RightToLeft -- 1: right to left
    • TopToBottom -- 2: top to bottom
    • BottomToTop -- 3: bottom to top

impl Direction

  • fn from_code(v: i64) -> Direction

  • fn code(self) -> i64

  • fn horizontal(self) -> bool whether the members stand side by side (else one above the other)

  • struct List a list's settings (msvSDListDirection, msvSDListSpacing, msvSDListAlignment)

    • direction: Direction
    • spacing: 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 number

  • fn 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) -> bool whether 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) -> bool whether 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) or Member -> Member

  • fn 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 list

  • fn 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 stencil src: an instance of each of its starting items (masters of src by NameU, names in language lang) as its items in that order, the list laid out -> the new items. A list that has items already, or that names a master src lacks, 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 master m of the document at page point at, 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 members

  • fn 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 of

  • fn list_of(doc: &Document, s: ShapeRef) -> Option<ShapeRef> the list a shape is an item of

  • fn callouts_of(doc: &Document, t: ShapeRef) -> Vec<ShapeRef> the callouts tied to a shape

  • fn target_of(doc: &Document, callout: ShapeRef) -> Option<ShapeRef> the target of a callout

  • fn 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 is

  • fn remove_members(tx: &mut Transaction, eng: &mut Engine, c: ShapeRef, shapes: &[ShapeRef]) -> Result<(), EditError> take shapes out of a container

  • fn 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 page

  • fn 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) -> bool whether a shape may join containers by its position: 2D, no guide, no callout, no heading, not a connector

  • fn accepts(doc: &Document, c: ShapeRef, s: ShapeRef) -> bool whether container c takes shape s (categories; never itself or one that holds it)

  • fn accepts_item(doc: &Document, l: ShapeRef, s: ShapeRef) -> bool whether list l takes shape s as an item (msvSDListRequiredCategories, msvSDListExcludedCategories); else it may still take it as a plain member

  • fn within(doc: &Document, inner: ShapeRef, outer: ShapeRef) -> bool whether inner is (transitively) a member of outer

  • fn drop_targets(doc: &Document, owner: Owner, s: ShapeRef, moving: &[ShapeRef]) -> Vec<ShapeRef> the containers on owner a shape joins where it lies now, leaving out moving (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 item

  • fn 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 first

  • fn 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 heading

  • fn fit(tx: &mut Transaction, eng: &mut Engine, c: ShapeRef, shrink: bool) -> Result<bool, EditError> fit a container around its members: grow only (shrink false) or exactly; an empty or turned container stays -> whether it changed

  • fn 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 moved

  • fn list_index_at(doc: &Document, l: ShapeRef, p: [f64; 2], leave_out: &[ShapeRef]) -> usize where a shape at page point p goes in a list: the index of the first member whose middle lies beyond p along the list's direction

  • struct Mark a 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 gets

    • at: [f64; 2]
    • to: [f64; 2] -- the far end of the insertion bar across the list
    • direction: Direction
    • index: usize
  • fn insert_marks(doc: &Document, l: ShapeRef) -> Vec<Mark> the marks of a list: before the first member, between members, after the last

  • fn insert_marks_without(doc: &Document, l: ShapeRef, leave_out: &[ShapeRef]) -> Vec<Mark> the marks of a list as if leave_out (an item being dragged) were not in it

  • fn 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 out

  • fn settle(tx: &mut Transaction, eng: &mut Engine, owner: Owner, shapes: &[ShapeRef], membership: bool) -> Result<Vec<ShapeRef>, EditError> after shapes were dropped, moved, resized or turned (what they carried moved with them): with membership the 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> before deleted go: 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 it

  • fn 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; shapes limits 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 target

  • fn set_anchor(tx: &mut Transaction, callout: ShapeRef, p: [f64; 2]) -> Result<(), EditError> remember where on its target a callout points (the page point p)

  • 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 point

  • fn 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 target

  • fn 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 show

  • fn user_addr(doc: &Document, name: &str) -> Option<CellAddr> a User cell's address (for the formula engine's dependencies)

Source: docs/API.md in the JFLib repository.