JFLib

diagram_core/src/route_edit.rs#

Source: lib/diagram_core/src/route_edit.rs

route_edit -- (JD21, CN-04) the way of a dynamic connector by hand: the handles of a selected
connector (a midpoint on every piece, a vertex at every bend), a piece moved across (right
angles stay right angles; next to an end a jog keeps the end where it is), a bend moved, added
and removed; the way kept afterwards when its shapes move

  way(doc, c) -> Option<Way>        the corners of the drawn way on the page and whether it is
                                    right-angled (None: no dynamic connector, curved, LockVtxEdit)
  handles(doc, c) -> Vec<Handle>    the midpoints and vertices to show (page coordinates)
  move_piece(&pts, i, to, right, stub, snap) / move_bend(&pts, j, ..) / add_bend(&pts, at)
  / remove_bend(&pts, j, right, stub) -> new points        pure, the ends stay
  edit(tx, eng, c, Edit, snap) -> changed   one of them on the connector: the way written,
                                    ConFixedCode 1 (2 stays)
  set_way(tx, eng, c, &pts)         a way written as given (ends must be the connector's)
  reset(tx, eng, &connectors)       Verbinder zurücksetzen: ConFixedCode 1 -> 0, routed anew
  kept(..) / kept_polyline(..)      (crate, glue::route_one) a kept way after its shapes moved

Visio's rules -- belegt (Visio 2000 user's guide, chapter 6, "Working with routable connectors";
support.microsoft.com "Edit connector lines, arrows, or points"; Microsoft Learn ConFixedCode):
routable connectors show midpoints and vertices besides their endpoints; their paths are edited
"by moving, adding, or deleting endpoints, midpoints, and vertices"; "to reroute a connector,
select it, and then drag a midpoint to a new location"; vertices are added with Ctrl + click and
deleted with Del after a click on them (the pencil tool, as for other shapes); ConFixedCode 1 is
"reroute as needed (manual reroute)", 2 "never reroute", 3 "reroute on crossover", 4 .. 6
"internal".  The local corpus: the connectors on the pages have 0 (from the style), 3, 4, 5 or 6
(Visio writes them when it routes), never 1 or 2: they reroute freely here as before.

Angenommen (the user's check in Visio may correct it):
* A right-angle way: a midpoint moves its piece across only; where the piece meets the end, a
  short stub (the routing clearance, at most a third of the piece) stays at the end and a jog
  carries the moved piece (two new bends); a piece next to an end's stub cannot be dragged past
  it.  A piece that comes within `snap` of the line of a parallel piece two further on, or of an
  end, snaps to it, and the bends between them go (that is how bends are removed by dragging).
  A vertex moves the two pieces at it.  Ctrl + click adds a vertex on the piece (a right-angle
  way: the piece is split; drag the vertex or a half to make a step).  Del removes a vertex: on a
  right-angle way with its neighbour, the jog between them flattened by moving the piece after
  (or before) them onto the line of the piece before (after) -- not where that piece ends at an
  end of the connector.
* A straight way (straight, network, centre to centre): dragging a midpoint makes a new vertex
  there; vertices move freely and are removed with Del.  Curved connectors have no handles.
* A way edited by hand gets ConFixedCode 1 (Visio's "manual reroute"; 2 stays).  Kept ways (1,
  2) keep their corners when their shapes move: the first and last pieces follow the ends, a
  dynamic end stays on the side the way leaves by.  1 is laid anew when the kept way now runs
  through a shape or an end piece would run back into its shape; 2 never.  Verbinder
  zurücksetzen gives ConFixedCode 1 back as 0 and routes anew.
  • struct Way the drawn way of a connector by hand

    • pts: Vec<[f64; 2]> -- its corners on the page, Begin first
    • right: bool -- right angles (a right-angle style and every piece upright or level); else a polyline
  • struct Handle a handle of a connector's way

    • at: [f64; 2] -- where it is (page)
    • bend: bool -- a vertex (true) or a piece's midpoint (false)
    • index: usize -- the vertex's index into Way::pts, or the piece's (the piece from pts[index])
    • half: [f64; 2] -- a midpoint: half the piece, from the handle to its end (page); a vertex: 0, 0
    • free: bool -- a midpoint that moves anywhere (a straight way: a new vertex), not only across
  • enum Edit one change by hand

    • Piece(usize, [f64; 2]) -- the piece from pts[i] moves (across, or a new vertex on a straight way) to to
    • Bend(usize, [f64; 2]) -- vertex pts[j] moves to to
    • Add([f64; 2]) -- a vertex on the piece nearest to the point
    • Remove(usize) -- vertex pts[j] goes
  • fn orthogonal(pts: &[[f64; 2]]) -> bool whether every piece is level or upright (pieces without length count as either)

  • fn way(doc: &Document, c: ShapeRef) -> Option<Way> the way of a connector that can be edited by hand: a dynamic connector, not curved, not locked against vertex edits (LockVtxEdit)

  • fn handles(doc: &Document, c: ShapeRef) -> Vec<Handle> the handles a selected connector shows: a vertex at every bend, a midpoint on every piece

  • fn move_piece(pts: &[[f64; 2]], i: usize, to: [f64; 2], right: bool, stub: f64, snap: f64) -> Vec<[f64; 2]> the way with piece i (from pts[i]) dragged to to: a right-angle way moves the piece across (snapped within snap, jogs at the ends with stubs of stub), a straight one gets a vertex at to

  • fn move_bend(pts: &[[f64; 2]], j: usize, to: [f64; 2], right: bool, stub: f64, snap: f64) -> Vec<[f64; 2]> the way with vertex pts[j] dragged to to: on a right-angle way the two pieces at it move across (at a vertex that only splits a piece: the piece after it), else the vertex moves

  • fn add_bend(pts: &[[f64; 2]], at: [f64; 2]) -> Option<Vec<[f64; 2]>> the way with a new vertex on the piece nearest to at (where at falls onto it; a right-angle way: the piece is split there) -> None: on a vertex or an end already

  • fn remove_bend(pts: &[[f64; 2]], j: usize, right: bool, stub: f64) -> Option<Vec<[f64; 2]>> the way without vertex pts[j] (see the file header) -> None: it cannot go

  • fn set_way(tx: &mut Transaction, eng: &mut Engine, c: ShapeRef, pts: &[[f64; 2]]) -> Result<(), EditError> write a way into a connector as given (Begin first; the ends must be where the connector's are) and mark it as the user's (ConFixedCode 1, unless it is 1 or 2 already)

  • fn edit(tx: &mut Transaction, eng: &mut Engine, c: ShapeRef, e: Edit, snap: f64) -> Result<bool, EditError> apply one change by hand to a connector's way (snap: how near a piece snaps to a line, in drawing units) -> whether the way changed

  • fn reset(tx: &mut Transaction, eng: &mut Engine, connectors: &[ShapeRef]) -> Result<(), EditError> Verbinder zurücksetzen: a way kept because it was edited by hand (ConFixedCode 1) is free again (0); the connectors are routed anew with few bends

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