diagram_core/src/replace.rs#
Source: lib/diagram_core/src/replace.rs
replace -- (JD21) Shape ändern (SP-11, RS-28, SH-G05): shapes replaced by instances of a master,
keeping what the user gave them -- place, size, text, shape data, format, glue, membership
Behavior::of(doc, shape) the Change Shape Behavior cells a replacement reads
can_replace(doc, shape, master) whether `shape` can become an instance of `master`
replace(tx, eng, shapes, master, lang) -> Vec<ShapeRef> every shape that can, replaced; the
new shapes in the order given
class(doc, sheet) User.msvReplaceClass (the gallery offers the same class)
Visio's rules (belegt: learn.microsoft.com "Change Shape Behavior Section", ReplaceLockFormat,
ReplaceLockText, ReplaceLockShapeData, ReplaceCopyCells; Visio blog "Insights for developers
about Change Shape" (2012); support.microsoft.com "Replace one shape with another"):
* It works like deleting the old shape and dropping the new one (new ID, the master's name);
"position, connections, formatting, shape text, and shape data" stay. Only 2-D for 2-D and
1-D for 1-D; a container only by a container (the gallery offers containers only); list
shapes (a flowchart's lanes) are never replaced; LockReplace, PageLockReplace and
DocLockReplace refuse. User.msvReplaceClass narrows the gallery to masters of the same class.
* What moves over are the old shape's LOCAL values: shape data, text, format, and the cells of
Hyperlink, Layer, Protection, Alignment, Layout, 1-D Endpoints and Shape Transform. What it
inherits from its master does not. Actions, User cells, Controls, Geometry never move.
* The cells of the NEW master decide: ReplaceLockShapeData TRUE keeps the master's shape data,
ReplaceLockText TRUE the master's text (and its Character, Paragraph, Tabs, Text Fields and
Text Block Format), ReplaceLockFormat TRUE the master's format (Fill, Line, Quick Style, Theme,
Gradient, Bevel, Effects, gradient stops). ReplaceCopyCells = DEPENDSON(cell, ...) names
cells that are copied whatever the locks say (formula and value; value only where the new
shape lacks a cell the formula names).
Angenommen (the Gegenprobe checks): connectors glued to a connection point keep it when the new
shape has a point with that index, else they glue to the whole shape (dynamic) or let go (a
plain line); the new shape takes the old one's place in the z-order and in its group, its
container and list memberships, callouts and boundary edges (the Relationships of both sides);
a container keeps its members; the text's Character/Paragraph/Tabs/Field rows come with the
text; Text Transform does not move; a group's own styles move when they differ from its
master's (or it has no master); comments (kept as a raw part, HL-04) and data links (JD18)
stay with the old ID -- not yet carried over.
struct Behaviorthe cells of the Change Shape Behavior section (read from the new shape's master)lock_data: bool-- ReplaceLockShapeData: the master's shape data stayslock_text: bool-- ReplaceLockText: the master's text stayslock_format: bool-- ReplaceLockFormat: the master's format stayscopy: Vec<alloc::string::String>-- ReplaceCopyCells: the cells copied anyway (names as the formula writes them)
impl Behavior
fn of(doc: &Document, sheet: SheetRef) -> Behaviorthe behaviour cells of a shape sheet (with inheritance)fn class(doc: &Document, sheet: SheetRef) -> Option<alloc::string::String>User.msvReplaceClass of a sheet (None: none)fn can_replace(doc: &Document, shape: ShapeRef, master: MasterRef) -> boolwhethershapecan be replaced by an instance ofmaster(a master of the same document): 1-D for 1-D, 2-D for 2-D, a container only by a container, no list, no guide, no LockReplace / PageLockReplace / DocLockReplacefn replace(tx: &mut Transaction, eng: &mut Engine, shapes: &[ShapeRef], master: MasterRef, lang: usize) -> Result<Vec<ShapeRef>, EditError>replace every shape ofshapesthat can_replace allows by an instance ofmaster(a master of this document: instance::import_master first), Name in languagelang(instance::LANGS); see the head of this file -> the new shapes (the others are left alone)