JFLib

diagram_core/src/autoconn.rs#

Source: lib/diagram_core/src/autoconn.rs

autoconn -- (JD21) connectors that look after the shapes they join: a 2-D shape dropped on a
connector is put into the flow (connector splitting, CN-08) and the shapes after it make
room, a deleted shape takes its connectors along and the flow through it heals (CN-09),
placeable shapes move away from a dropped one (PlowCode, PR-09)

  page_splits(doc, page)            PageShapeSplit of the page (missing: on, Visio's default)
  splits(doc, shape)                ShapeSplit: a top-level 2-D shape that splits connectors
  splittable(doc, connector)        a dynamic connector with ShapeSplittable
  can_insert(doc, owner, shape)     splits and has no connector glued to it yet
  split_target(doc, owner, box, skip) -> Option<connector>   the connector a shape with this
                                    box (page) splits when it is dropped there
  split(tx, eng, connector, shape) -> new connector   Page.SplitConnector: the connector ends
                                    at the shape, a copy of it (without its text) runs from
                                    the shape to where it ended
  insert(tx, eng, owner, shape, connector, gap) -> Inserted   split, the shape lined up with
                                    the one before it, the shapes after it moved on as far as
                                    the room needs
  downstream(doc, owner, shape, stop) -> shapes   what follows a shape through connectors
  plow(tx, eng, owner, shapes, gap) -> moved   placeable shapes under the dropped ones move
                                    away (PlowCode / ShapePlowCode)
  heal(tx, eng, owner, deleted) -> Healed   before shapes are deleted: their connectors to
                                    delete as well, the flow through a shape joined again
  spacing(doc, page) -> [x, y]      the page's spacing between shapes (AvenueSizeX/Y)

Every point is on the page in drawing units (inches, y up).  Nothing runs on its own: the
app calls these when the user drops, pastes, moves or deletes (PLAN.md, "Fallen").

Visio's rules -- belegt (Microsoft Learn: the ShapeSplit, ShapeSplittable, PageShapeSplit,
PlowCode and ShapePlowCode cells; Page.SplitConnector, ApplicationSettings.
ConnectorSplittingEnabled and DeleteConnectorsEnabled, Shape.DeleteEx / VisDeleteFlags; the
Visio blog "Inserting and Deleting Shapes in Visio 2010"):
* Splitting needs all of: the app's option (Enable connector splitting), the page
  (PageShapeSplit 1, the default), the shape (ShapeSplit 1; a 2-D shape or a placeable 1-D
  one -- only 2-D here) and the connector (ShapeSplittable 1, a routable 1-D connector).
* SplitConnector "duplicates the connector (except for text), positions the shape
  automatically, and glues the shape to the two resulting connectors"; it returns the copy.
* A drop on a connector moves the shapes downstream of the insertion "just enough to make
  room"; a downstream shape beside the flow does not move; the new shape is aligned with the
  upstream shape and spaced from it.
* PlowCode 0 / 1: placeable shapes do not / do move away when a placeable shape is dropped
  near them (Page Setup › "Move other shapes away on drop"); ShapePlowCode 0 as the page
  says, 1 never, 2 always.
* Deleting a shape deletes the connectors glued to it (the app's option Delete connectors
  when deleting shapes) except connectors with text; the option "also determines whether two
  connectors reconnect when a shape to which they are both connected is deleted"; with more
  than one connector in and out the reconnection is ambiguous and nothing heals; the other
  shapes do not move to close the gap.

Angenommen (the user's check in Visio may correct it):
* The connector a dropped shape splits is a splittable connector on the page whose way
  crosses the shape's box while both its ends lie outside the box and the box overlaps none of
  the shapes it is glued to; among several the one whose way passes nearest the box's middle.
  A shape that already has a connector glued to it splits nothing (it is in a flow already).
* The original connector keeps its Begin and its text and ends at the shape; the copy starts
  at the shape and takes over the old End's glue (a connection point stays that point, a
  whole shape stays dynamic, a free end stays where it was).  Both glue to the dropped shape
  as a whole (dynamic glue).
* The flow's axis is the main direction from the shape before to the shape after (else from
  Begin to End).  The dropped shape's middle goes on the middle line of the shape before when
  their bands across the axis overlap, and at least the page's spacing (AvenueSizeX/Y) after
  it; when the shape after is then nearer than the spacing, it and the shapes downstream of it
  (through connectors Begin -> End) that do not lie before the dropped shape move on along
  the axis by what is missing.  Fixed shapes (ShapeFixedCode &H7, LockMoveX/Y), containers
  and shapes with ShapePlowCode 1 stay, and so does what lies only behind them.  This always
  comes with a split; PlowCode adds plowing for every drop.
* Plowing: a placeable top-level 2-D shape (no container, no member of one, no callout, not
  ObjType 4, not fixed) whose box overlaps a dropped shape's box moves the shortest way out of
  it to the page's spacing, and in turn pushes what it then overlaps (each shape moves once).
* Healing counts dynamic connectors only (plain lines lose their glue as before); a connector
  whose both ends are on the deleted shape is deleted; with exactly one connector in (End on
  the shape) and one out (Begin on it) the one coming in survives (the one going out when
  only that one has text; both with text: no healing) and takes the other one's far end; a
  heal that would join a shape to itself does not happen.  Healing runs through chains of
  deleted shapes.
  • fn page_splits(doc: &Document, page: PageRef) -> bool whether shapes split connectors on the page: PageShapeSplit (missing: yes, Visio's default)

  • fn splits(doc: &Document, s: ShapeRef) -> bool whether a shape splits connectors it is dropped on: a top-level 2-D shape (no guide, no container, no callout) with ShapeSplit 1

  • fn splittable(doc: &Document, c: ShapeRef) -> bool whether a connector can be split: a top-level dynamic connector with ShapeSplittable 1

  • fn can_insert(doc: &Document, owner: Owner, s: ShapeRef) -> bool whether a shape may be put into a connector: it splits, and no connector is glued to it yet

  • fn split_target(doc: &Document, owner: Owner, b: [f64; 4], skip: &[ShapeRef]) -> Option<ShapeRef> the connector a shape with box b (page) splits when dropped there: a splittable connector whose way crosses the box, both ends outside it, the box over none of the shapes it is glued to, nearest the box's middle; connectors glued to a shape of skip (the dropped shape and what moves with it) do not count

  • fn split(tx: &mut Transaction, eng: &mut Engine, c: ShapeRef, s: ShapeRef) -> Result<ShapeRef, EditError> split connector c with shape s (Visio's Page.SplitConnector): a copy of the connector without its text is made, c ends at s, the copy runs from s to where c ended (with that end's glue); both glue to s as a whole and route -> the copy. Invalid: c is no splittable connector, s is 1-D or elsewhere

  • struct Inserted what insert did

    • connector: ShapeRef -- the new connector (from the shape to the old End)
    • moved: Vec<ShapeRef> -- the shapes moved: the inserted one when it was lined up, those after it
  • fn downstream(doc: &Document, owner: Owner, from: ShapeRef, stop: &[ShapeRef]) -> Vec<ShapeRef> the shapes downstream of from through connectors (Begin on one, End on the next), top-level, in the order found (breadth first); stop are never entered

  • fn insert(tx: &mut Transaction, eng: &mut Engine, owner: Owner, s: ShapeRef, c: ShapeRef, gap: [f64; 2]) -> Result<Inserted, EditError> put shape s into connector c (a drop): split, s lined up with the shape before it and spaced from it, the shapes after it moved on along the flow where the room is short (gap: the page's spacing in x and y) -> the new connector and what moved; connectors follow

  • fn spacing(doc: &Document, page: PageRef) -> [f64; 2] the page's spacing between shapes in drawing units: AvenueSizeX/Y (Seite einrichten › Layout und Routing; Visio's metric default 7.5 mm), through the drawing scale

  • fn plows(doc: &Document, page: PageRef) -> bool whether a drop on the page may push shapes at all: PlowCode 1, or a shape on it with ShapePlowCode 2

  • fn plow(tx: &mut Transaction, eng: &mut Engine, owner: Owner, shapes: &[ShapeRef], gap: [f64; 2]) -> Result<Vec<ShapeRef>, EditError> the dropped shapes push the placeable shapes they cover out of the way (PlowCode of the page, ShapePlowCode of each shape): the shortest way out to the page's spacing gap, and what those then cover in turn; each shape moves once -> the moved shapes (connectors follow)

  • struct Healed what heal decided

    • gone: Vec<ShapeRef> -- connectors to delete with the shapes
    • joined: Vec<ShapeRef> -- connectors that now join the shapes before and after a deleted one: route them once the shapes are gone
  • fn heal(tx: &mut Transaction, eng: &mut Engine, owner: Owner, deleted: &[ShapeRef]) -> Result<Healed, EditError> before deleted are deleted (Visio's "Delete connectors when deleting shapes"): the dynamic connectors glued to a deleted 2-D shape go with it unless they have text; where exactly one comes in (End) and one goes out (Begin), one of them survives and joins the shapes before and after (the flow heals). Glues the survivors anew; the caller deletes gone with the shapes, detaches what stays and routes joined after the deletion

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