JFLib

diagram_core/src/groups.rs#

Source: lib/diagram_core/src/groups.rs

groups -- (JD21) how groups behave (SS-17, SP-06, SP-17, RS-27): the cells of the Group
Properties section, Zu Gruppe hinzufügen / Aus Gruppe entfernen, shapes dropped into a group,
the warning before a group is taken apart that formulas or a master bind

  props(doc, g) -> Props               SelectMode, DisplayMode, IsDropTarget, IsSnapTarget,
                                       IsTextEditTarget, DontMoveChildren (Visio's values when
                                       a cell is missing)
  set_props(tx, eng, g, &props)        the six cells written (constants, Behavior dialog)
  is_drop_source(doc, s) / set_drop_source(tx, eng, s, on)   IsDropSource (Miscellaneous)
  double_click_opens(doc, g) / set_double_click_opens(tx, eng, g, on)   EventDblClick
                                       OPENGROUPWIN() (Verhalten › Doppelklicken)
  text_target(doc, s) -> ShapeRef      where typing into a group goes (IsTextEditTarget)
  drop_target_at(doc, owner, p, skip)  the group a shape dropped at page point p joins
  dropped(tx, eng, owner, shapes)      shapes that may (IsDropSource) dropped onto a group
                                       that takes them (IsDropTarget) join it
  add_to_group(tx, eng, g, shapes)     Zu Gruppe hinzufügen: the shapes into the group, where
                                       they are on the page, the group's box around them
  remove_from_group(tx, eng, shapes)   Aus Gruppe entfernen: members out to the group's parent,
                                       just above the group, where they are on the page
  ungroup_warning(doc, g) -> Option<Warning>   what ungrouping loses (a master, formulas)
  guide_glue(tx, eng, owner, shapes)   (SP-17) glue between a guide and shapes breaks unless
                                       both go into a group
  reparent(tx, eng, s, to, pos)        a shape into another parent, its place on the page kept

Visio's rules (belegt: learn.microsoft.com, cells of the Group Properties section, IsDropSource,
"Controlling the Behavior of Groups" of the Visio 2002 developer reference, the Behavior dialog
box on support.microsoft.com, Selection.AddToGroup / RemoveFromGroup / ConvertToGroup, the
Visio User's Guide ch. 4 "Working with shapes in groups"):
* SelectMode 0: a click selects the group only; 1 (default): the group first, a later click a
  member; 2: the member under the pointer first, a later click the group ("click the bounding
  box to select the group itself"); nested groups follow the selected group's mode.
* DisplayMode 0 hides the group's own geometry and text, 1 draws it behind the members, 2 (the
  default) in front (render.rs since JD4).
* IsDropTarget (Accept dropped shapes) takes a dropped shape only when the shape's IsDropSource
  (Add shape to groups on drop) is set too; both default to FALSE.
* IsSnapTarget (Snap to member shapes, default TRUE): shapes snap and glue to the members;
  FALSE: only to the group.  IsTextEditTarget (Edit text of group, default TRUE since Visio
  2000): typing goes into the group's text; FALSE: into the member on top of the stacking order.
* DontMoveChildren: members cannot be dragged with the mouse (other ways still move them).
* AddToGroup: the selection holds the shapes and the group, the group is the primary selection
  or the only group.  RemoveFromGroup: the subselected members leave the group.
* Guides: "If you add a guide and the shapes glued to it to a group, be sure to select both ...;
  otherwise the glue breaks" (UG ch. 4).
* Bitmaps: the old guide says imported bitmaps do not turn with a group; Visio 2010 and later
  turn pictures (Bild › Drehen, the rotation handle) -- kept: they turn (not built, on purpose).
* In Gruppe umwandeln (ConvertToGroup) turns a metafile into shapes; the model keeps metafiles
  as bytes it does not draw (render Note::Metafile), so there is nothing to convert yet.
Angenommen (the Gegenprobe checks): the alignment box follows after Zu Gruppe hinzufügen and Aus
Gruppe entfernen (update_alignment_box; not with LockCalcWH); a group left without members and
without geometry of its own goes; added shapes go on top of the members in their page order and
leave containers and lists they were in; members of an instance of a master (subshapes that
inherit from its master) stay; a dropped shape joins when its middle lies in the frame of the
topmost top-level shape under it and that shape is a group taking drops.
  • enum SelectMode how a click selects in a group (SelectMode)
    • GroupOnly -- 0: only the group
    • GroupFirst -- 1: the group first, then a member (Visio's default)
    • MembersFirst -- 2: the member under the pointer first, then the group

impl SelectMode

  • fn code(self) -> u8 the cell's value

  • fn of(v: i64) -> SelectMode the mode of a cell's value (unknown: group first)

  • struct Props the cells of a group's Group Properties section

    • select_mode: SelectMode
    • display_mode: u8 -- DisplayMode: 0 the group's own geometry and text hidden, 1 behind the members, 2 in front
    • drop_target: bool -- IsDropTarget: takes shapes dropped onto it (with IsDropSource)
    • snap_target: bool -- IsSnapTarget: shapes snap and glue to the members
    • text_edit_target: bool -- IsTextEditTarget: typing goes into the group's own text
    • dont_move_children: bool -- DontMoveChildren: members cannot be dragged
  • fn is_group(doc: &Document, s: ShapeRef) -> bool whether the shape is a group

  • fn props(doc: &Document, g: ShapeRef) -> Props the Group Properties of a shape (Visio's values for missing cells)

  • fn set_props(tx: &mut Transaction, eng: &mut Engine, g: ShapeRef, p: &Props) -> Result<(), EditError> write a group's Group Properties (only the cells that change; booleans as TRUE/FALSE values)

  • fn is_drop_source(doc: &Document, s: ShapeRef) -> bool IsDropSource: the shape joins a group it is dropped onto (when the group takes drops)

  • fn set_drop_source(tx: &mut Transaction, eng: &mut Engine, s: ShapeRef, on: bool) -> Result<(), EditError> set IsDropSource of a shape

  • fn double_click_opens(doc: &Document, g: ShapeRef) -> bool whether a double click opens the group (its EventDblClick calls OPENGROUPWIN)

  • fn set_double_click_opens(tx: &mut Transaction, eng: &mut Engine, g: ShapeRef, on: bool) -> Result<(), EditError> a double click opens the group (EventDblClick = OPENGROUPWIN()) or does what it did before (off: the cell inherits again, else 0 -- Visio's "Bearbeitet Text des Shapes")

  • fn text_target(doc: &Document, s: ShapeRef) -> ShapeRef where typing into shape s goes: a group whose IsTextEditTarget is off hands it to its member on top of the stacking order (and so on down)

  • fn drop_target_at(doc: &Document, owner: Owner, p: [f64; 2], skip: &[ShapeRef]) -> Option<ShapeRef> the group a shape dropped at page point p joins: the topmost top-level shape of owner (not in skip, no guide, no 1-D shape) whose frame holds p, when it is a group that takes drops (IsDropTarget)

  • fn dropped(tx: &mut Transaction, eng: &mut Engine, owner: Owner, shapes: &[ShapeRef]) -> Result<Vec<ShapeRef>, EditError> shapes dropped or moved: each top-level one with IsDropSource whose middle lies on a group that takes drops joins that group (add_to_group) -> the groups that took shapes

  • fn reparent(tx: &mut Transaction, eng: &mut Engine, s: ShapeRef, to: Option<ShapeRef>, pos: Option<usize>) -> Result<(), EditError> put shape s into parent to (None: the page) at pos in its z-order (None: on top), where it is on the page: its pin, angle and flips (1-D: its ends) in the new parent's coordinates; formulas of it and its subshapes that name its old group become their values

  • fn add_to_group(tx: &mut Transaction, eng: &mut Engine, g: ShapeRef, shapes: &[ShapeRef]) -> Result<Vec<ShapeRef>, EditError> Zu Gruppe hinzufügen: shapes (not the group, nothing it holds or that holds it, no inheriting subshape of an instance) go into group g on top of its members, where they are on the page; they get the formulas of members (PinX "Sheet.<g>!Width*k" ...), leave the containers and lists they were in, and the group's box fits them all (update_alignment_box). Glue between a guide and shapes breaks unless both are in the group -> the shapes added

  • fn remove_from_group(tx: &mut Transaction, eng: &mut Engine, shapes: &[ShapeRef]) -> Result<Vec<ShapeRef>, EditError> Aus Gruppe entfernen: members (not an inheriting subshape of an instance) go to their group's parent just above the group, where they are on the page; the group's box fits the members that stay, a group left without members and without geometry of its own goes -> the shapes moved

  • enum Warning what ungrouping a group loses (the app asks first)

    • Master -- the group is an instance of a master: its link to the master goes (Visio's warning)
    • Formulas(usize) -- this many cells of members name the group in formulas that are not their place or size (Sheet.N!Prop.X, Sheet.N!User.Y ...): they keep their values only
  • fn ungroup_warning(doc: &Document, g: ShapeRef) -> Option<Warning> what ungrouping g would lose (None: nothing)

  • fn guide_glue(tx: &mut Transaction, eng: &mut Engine, owner: Owner, moving: &[ShapeRef], together: &[ShapeRef]) -> Result<(), EditError> (SP-17) the glue between a guide and a shape breaks when one of them is among moving (what goes into a group or out of it) and the other is not among together (what ends up beside it): the glued cells keep their values, the Connect entry goes

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