diagram_core/src/glue.rs#
Source: lib/diagram_core/src/glue.rs
glue -- connection points, glue and the dynamic connector (CN-01..05, CN-12, CN-15)
connection_points(doc, shape) -> Vec<ConnPoint> the Connection rows on the page: point,
direction (into the shape, as DirX/DirY mean it), Type
glued(doc, shape) -> [Target; 2] what Begin and End are glued to (the Connect entries; glue
to a guide reads as None: pointglue.rs)
ends(doc, shape) Begin and End on the page
is_one_d / is_connector a 1-D shape / one that routes (ObjType routable)
style(doc, shape) -> Style right angle, straight or curved (its cells, else the page's)
path(doc, shape) -> points the drawn way on the page (curves flattened)
glue(tx, eng, shape, end, at, to) put an end at `at` and glue it (Target::None: free)
new_connector(tx, eng, owner, (at, to), (at, to)) / new_line(..) new 1-D shapes
dependents(doc, owner, &moved) the 1-D shapes glued to these shapes (or moved with them)
update(tx, eng, &shapes) their ends follow, connectors route again (one gesture)
reset(tx, eng, &connectors) route again, also where ConFixedCode keeps the way
set_style(tx, eng, &connectors, style)
detach(tx, eng, owner, &deleted) before deleting shapes: glue to them becomes constants
Every point here is on the page in drawing units (y up); the cells hold the connector's
parent coordinates (the page, or its group's local ones), the Geometry rows its local ones.
The file's record of glue (CN-15), as Visio writes it ([MS-VSDX] Connect_Type and the cells
of the 1-D Endpoints, Glue Info and Shape Layout sections; checked against Visio's own files):
* static glue of Begin to connection point k (row IX k-1) of shape N:
BeginX, BeginY = PAR(PNT(Sheet.N!Connections.Xk,Sheet.N!Connections.Yk))
BegTrigger = _XFTRIGGER(Sheet.N!EventXFMod)
Connect FromSheet=<id> FromCell=BeginX FromPart=9 ToSheet=N ToCell=Connections.Xk
ToPart=100+k-1
(End: EndX, EndY, EndTrigger, FromCell=EndX, FromPart=12)
* dynamic glue (to the whole shape): BeginX, BeginY = _WALKGLUE(BegTrigger,EndTrigger,
WalkPreference), EndX, EndY = _WALKGLUE(EndTrigger,BegTrigger,WalkPreference), the trigger as
above, Connect ToCell=PinX ToPart=3; the engine cannot compute _WALKGLUE, so the value comes
from here (Transaction::set_result, the formula stays)
* a free end: a constant, its trigger _XFTRIGGER(EventXFMod); one Connect per glued end.
The static formulas the engine computes itself: after the target moved, its recalculation has
moved the end already; update() asks it again and then routes.
The dynamic connector (ObjType 2 = routable, GlueType 2 = walking glue allowed) keeps its box
on the line from Begin to End: PinX = GUARD((BeginX+EndX)/2), Width = GUARD(EndX-BeginX),
LocPinX = GUARD(Width*0.5), Angle = GUARD(0DA), y alike; a side shorter than 5 mm becomes
GUARD(+-0.19685039370079DL) as in Visio's files. Its way is one Geometry section: MoveTo at
Begin, a LineTo per corner, the last at End, constants in local coordinates (the curved style:
MoveTo and one NURBSTo over the corners). Controls.TextPosition goes to the middle of the
way. Rows of a master keep their indices where their type fits; else they get a Del mark
and new rows follow.
Dynamic glue docks on the outline of the target (the farthest point of its geometry on a line
through it). (JD21v) Where on it, and the way, the connector's routing style decides as Visio
16 does (route_styles::route, checked against Visio's own ways): right angles straight across
in the middle of the overlap of two shapes beside each other, else an L leaving the begin's top
or bottom; around obstacles in the free part of the sides; else the cheapest way over the sides
(length + bends; route::best_through, which is also all ends glued to points or free get); where
the other end lies within a side's reach, the point straight opposite it is offered too.
(JD15, SS-18) WalkPreference changes none of these ways in Visio: kept, not read. Obstacles
are, as in Visio 16 (JD21v), the placeable shapes (ObjType with bit 1, not 4; a group with 8 by
its placeable members; obstacles()), and for each connector the shapes its ends are glued to;
the clearance is half the page's AvenueSize (opts_for). The legs of Visio's right-angle router
keep out of the way of the other connectors glued to the same shapes (related_lines: Visio
spreads connectors leaving one side); after a move the connectors a placeable shape now crowds
route again (crowded). After routing ConFixedCode becomes 6 or 0 as
Visio writes it (route_styles::mark). ConFixedCode 1 and 2 (reroute manually / never) keep the
corners and only move the first and last pieces; reset() routes them anew. (JD21) 1 is laid
anew when the kept way runs through a shape (route_edit.rs); 3 .. 6 route freely (Visio writes
them for the connectors it routes itself); ShapePermeableX/Y let ways cross a shape.
(JD21v) After routing, the line jumps of the connectors laid and of the connectors they cross
go into their Geometry (jumps.rs, as Visio writes them); detach takes the jumps over deleted
connectors away; path() reads a connector's way without them.
Nothing happens on its own: opening a file routes nothing, only the shapes handed to update.
struct ConnPointa connection point of a shape on the pagerow: u32-- IX of its row (Connections.X<row + 1>)at: [f64; 2]-- where it is on the pagedir: Option<[f64; 2]>-- DirX/DirY turned onto the page, unit length: the direction the point faces into the shape (a connector arrives along it, a route leaves against it); None: 0, 0kind: u8-- Type: 0 inward, 1 outward, 2 both
enum Targetwhat an end of a 1-D shape is glued toNone-- nothing: a free endPoint { shape: ShapeRef, row: u32, }-- a connection point (static glue): the shape and the IX of its Connection rowShape(ShapeRef)-- the whole shape (dynamic glue)
enum Endan end of a 1-D shapeBegin-- BeginX, BeginYEnd-- EndX, EndY
enum Stylehow a dynamic connector draws its wayRightAngle-- right angles around obstacles (the default)Straight-- one straight lineCurved-- a curve over the corners of the right-angle way
fn connection_points(doc: &Document, shape: ShapeRef) -> Vec<ConnPoint>the connection points of a shape (its Connection rows with inheritance) on the pagefn is_one_d(doc: &Document, shape: ShapeRef) -> boolwhether the shape is 1-D (it has BeginX)fn is_connector(doc: &Document, shape: ShapeRef) -> boolwhether the shape is a dynamic connector: 1-D and routable (ObjType has the routable flag)fn ends(doc: &Document, shape: ShapeRef) -> Option<([f64; 2], [f64; 2])>Begin and End of a 1-D shape on the pagefn glued(doc: &Document, shape: ShapeRef) -> [Target; 2]what Begin and End are glued to, from the Connect entries of the page or master (glue to something else -- a guide, a vertex -- reads as None)fn style(doc: &Document, shape: ShapeRef) -> Stylehow a dynamic connector draws its way: ConLineRouteExt 2 curved, ShapeRouteStyle 2 or 16 straight, else right angles; 0 asks the page (LineRouteExt, RouteStyle)fn path(doc: &Document, shape: ShapeRef) -> Vec<[f64; 2]>the drawn way of a shape on the page: the first shown Geometry section, curves flattened; (JD21 jumps) a connector's way without its line jumps (jumps::way)fn glue(tx: &mut Transaction, eng: &mut Engine, shape: ShapeRef, end: End, at: [f64; 2], to: Target) -> Result<(), EditError>put an end of a 1-D shape atat(page coordinates) and glue it toto: a connection point (static: PAR(PNT(..)) formulas), a whole shape (dynamic, connectors and walking glue only: _WALKGLUE), or nothing (constants); the Connect entries of the end are replaced. A dynamic connector routes again. Invalid: not 1-D, a target on another page or inside the shape, dynamic glue for a plain line; NoRow: no such connection pointfn dependents(doc: &Document, owner: Owner, moved: &[ShapeRef]) -> Vec<ShapeRef>the 1-D shapes to update after these shapes moved (or were resized, turned ...): the ones glued to them or to shapes inside them, and glued ones among them; in Connect orderfn detach(tx: &mut Transaction, eng: &mut Engine, owner: Owner, deleted: &[ShapeRef]) -> Result<(), EditError>before shapes are deleted: the glue of other shapes to them (or to shapes inside them) ends -- the glued cells keep their values as constants, triggers point to the shape itself, the Connect entries go (Transaction::delete_shapes removes the deleted shapes' own)fn new_connector(tx: &mut Transaction, eng: &mut Engine, owner: Owner, begin: ([f64; 2], Target), end: ([f64; 2], Target)) -> Result<ShapeRef, EditError>add a dynamic connector on a page or in a master (no master shape: every cell of its own, the style "Connector" when the document has one) frombegintoend(page coordinates) glued to the targets, routed -> its handle. On an error the transaction holds what was done so far: drop itfn new_line(tx: &mut Transaction, eng: &mut Engine, owner: Owner, begin: ([f64; 2], Target), end: ([f64; 2], Target)) -> Result<ShapeRef, EditError>add a straight line (1-D, not routed: CN-12) frombegintoend, glued to connection points (Target::Shape is refused: lines glue statically); its Geometry follows Width, so it keeps its form when an end moves -> its handlefn update(tx: &mut Transaction, eng: &mut Engine, shapes: &[ShapeRef]) -> Result<(), EditError>after a gesture: the ends of these 1-D shapes follow what they are glued to (static ends through the engine, dynamic ones dock anew) and dynamic connectors route again; lines keep their form. Only these shapes changefn reset(tx: &mut Transaction, eng: &mut Engine, connectors: &[ShapeRef]) -> Result<(), EditError>"Verbinder zurücksetzen": route these connectors anew with few bends, also the ones whose way ConFixedCode keepsfn set_style(tx: &mut Transaction, eng: &mut Engine, connectors: &[ShapeRef], style: Style) -> Result<(), EditError>give these connectors a style (ShapeRouteStyle and ConLineRouteExt: right angle 1/1, straight 16/1, curved 1/2) and route them anewfn crowded(doc: &Document, owner: Owner, shapes: &[ShapeRef]) -> Vec<ShapeRef>(JD21v) the dynamic connectors whose way runs through one of these shapes, or closer to it than the clearance (half the page's AvenueSize), where the shape keeps connectors out (an obstacle: placeable, ObjType 1; a group with 8 by its placeable members): after the shapes moved Visio routes them again (the counter-check visio-obst-1 [sprd] "beside": a way 0.05 in under a shape moved next to it went round it anew); the shapes themselves are not in the list