JFLib

diagram_core/src/tools/number.rs#

Source: lib/diagram_core/src/tools/number.rs

tools::number -- Shapes nummerieren (AS-11, RA-09): numbers in the shapes' texts

  Order               Selection (as given), Rows (left to right, then top to bottom), Columns
                      (top to bottom, then left to right), Connections (along the connectors)
  Place               Before the text, After it, Instead of it
  Numbering           start, step, prefix, place
  order(doc, shapes, by) -> Vec<ShapeRef>     the shapes in the order they get their numbers
  label(prefix, n)    the text a number shows: "S-" and 3 -> "S-3"
  number(tx, eng, shapes, &numbering) -> next   the numbers written (one shape after the
                      other, step by step) -> the number the next shape would get
  set_number(tx, eng, s, text, place)     one shape's number (an earlier one replaced)
  remove(tx, eng, s)  the number taken out of the text again
  on_drop(doc, page) / keep_on_drop(tx, page, Some(&numbering) | None) / dropped(tx, eng, s)
                      a page that numbers shapes as they are dropped: the settings and the next
                      number in User cells of the page sheet; dropped() gives a dropped shape the
                      next number and counts on

Rules (Visio's add-on is a program; these are chosen and named here):
* The number is plain text: before the text it is followed by a space ("3 Prüfen"), after it it
  follows one ("Prüfen 3"), instead of it it is the whole text.  The characters' formatting
  stays: the number goes into the first (last) run of characters.
* User.JFD_Number keeps the number text written and User.JFD_NumberPlace where (0 before, 1
  after, 2 instead): numbering again takes the old number out first, so a shape never carries
  two.  A text the user changed so that the old number is gone is taken as it is.
* Rows: the shapes are sorted by their middles from top to bottom; a shape whose middle lies
  within the height of the first shape of the current row joins that row, else it starts the
  next; each row runs from left to right.  Columns alike with the axes swapped.
* Connections: the shapes in the order of the flow -- a shape gets its number once every shape
  with a connector to it (Begin -> End) has one; among the shapes that are ready the one first in
  rows comes first; in a loop the first shape in rows that is left goes on.  Shapes without
  connectors are ready from the start.
* A shape whose text is locked (LockTextEdit) is left out and takes no number.
/// User cell: the number text a shape got (prefix and number)
NUMBER_CELL: &str = "JFD_Number"
/// User cell: where it went (Place::code)
PLACE_CELL: &str = "JFD_NumberPlace"
/// User cells of the page sheet while the page numbers shapes as they are dropped: the next
/// number, the step, the prefix, the place
NEXT_CELL: &str = "JFD_NumberNext"
STEP_CELL: &str = "JFD_NumberStep"
PREFIX_CELL: &str = "JFD_NumberPrefix"
DROP_PLACE_CELL: &str = "JFD_NumberDropPlace"
  • enum Order the order the shapes get their numbers in

    • Selection -- as given (the order the user selected them in)
    • Rows -- left to right, then top to bottom
    • Columns -- top to bottom, then left to right
    • Connections -- along the connectors (Begin -> End)
  • enum Place where the number goes in the text

    • Before -- in front of the text, a space between
    • After -- after the text, a space between
    • Instead -- the number is the whole text

impl Place

  • fn code(self) -> u8 the code of User.JFD_NumberPlace

  • fn from_code(c: f64) -> Place the place of a code (anything else: Before)

  • struct Numbering how shapes are numbered

    • start: i64 -- the first number
    • step: i64 -- added for every next shape (may be negative)
    • prefix: String -- the text before the number ("S-", "Schritt ")
    • place: Place
  • fn label(prefix: &str, n: i64) -> String the text a number shows

  • fn order(doc: &Document, shapes: &[ShapeRef], by: Order) -> Vec<ShapeRef> the shapes in the order they get their numbers

  • fn set_number(tx: &mut Transaction, eng: &mut Engine, s: ShapeRef, num: &str, place: Place) -> Result<(), EditError> give shape s the number text num at place, an earlier number taken out first

  • fn remove(tx: &mut Transaction, eng: &mut Engine, s: ShapeRef) -> Result<(), EditError> take a shape's number out of its text again (the User cells stay, empty)

  • fn number(tx: &mut Transaction, eng: &mut Engine, shapes: &[ShapeRef], n: &Numbering) -> Result<i64, EditError> number shapes in the order given -> the number the next shape would get; shapes whose text is locked are left out

  • fn on_drop(doc: &Document, page: PageRef) -> Option<Numbering> the page numbers shapes as they are dropped: its numbering (start = the next number)

  • fn keep_on_drop(tx: &mut Transaction, page: PageRef, n: Option<&Numbering>) -> Result<(), EditError> the page numbers dropped shapes from n.start on (None: no more); the page sheet's User cells

  • fn dropped(tx: &mut Transaction, eng: &mut Engine, s: ShapeRef) -> Result<bool, EditError> a shape dropped on a page that numbers dropped shapes gets the next number, the page counts on -> whether it got one

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