JFLib

diagram_core/src/ops/clip.rs#

Source: lib/diagram_core/src/ops/clip.rs

ops::clip -- copy and paste of shapes inside the app

  copy(doc, shapes) -> Clip                     the shapes with their subshapes, as top-level
                                                shapes (a subshape takes its groups'
                                                transforms into its own cells)
  paste(tx, eng, owner, &clip, offset)          the copies on a page or in a master, moved by
                                                `offset` -> the new top-level shapes

Pasted shapes get new IDs; the formulas of the pasted shapes that name a copied shape by
Sheet.N (or by a NameU that ends in .N) name its copy, Names and NameUs that end in .<old ID>
end in the new one, UniqueIDs are dropped, the Connect entries between copied shapes come
along with the new IDs.  Glue to a shape outside the copy is let go: the glued cells keep
their values as constants, the Connect entry stays behind.  (JD8 rest, LY-03) The layers of
the page the shapes were copied from come along by name: on another page the missing ones are
added (with their Visible, Print, Lock, Snap, Glue, Color, ColorTrans) and the copies' own
LayerMember cells name the target page's indices.  A Clip holds the document's
string handles and refers to its masters and styles by ID: it pastes into the document it
was copied from (an app with several documents copies across them through a file format).
  • struct Clip copied shapes (copy), ready to paste

impl Clip

  • fn is_empty(&self) -> bool whether nothing was copied

  • fn len(&self) -> usize the number of top-level shapes in it

  • fn bounds(&self) -> Option<[f64; 4]> the box of the copied shapes on the page where they were copied

  • fn copy(doc: &Document, shapes: &[ShapeRef]) -> Clip copy shapes with their subshapes (shapes inside another one of the list go with it); a subshape becomes a top-level shape with its groups' transforms in its own pin, angle and flips (1D: its ends)

  • fn paste(tx: &mut Transaction, eng: &mut Engine, owner: Owner, clip: &Clip, offset: [f64; 2]) -> Result<Vec<ShapeRef>, EditError> paste copied shapes on a page or in a master (into the document they were copied from), on top of its shapes and moved by offset (page) -> the new top-level shapes

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