JFLib

diagram_core/src/cell.rs#

Source: lib/diagram_core/src/cell.rs

cell -- one ShapeSheet cell as the file keeps it: name, formula, cached value, unit, error

  Cell::new(name)                    no value, no formula attribute
  Cell { name, value, formula, unit, error, stale }
  Value::Num(f64) / Text(Sym) / Absent      the cached value V (internal units)
  Formula::Absent / Inherited / NoFormula / Expr(Sym)
  CellError::parse("#REF!")          the error state E
  Origin                             where a cell's formula comes from (local, master shape,
                                     style, default) or that its row was deleted

Formula and value are a pair (PLAN.md, "Fallen"):
* Formula::Absent -- no F attribute: the value itself is the formula, a constant shown in U.
* Formula::Expr -- F holds an expression; V is its last result.  A formula the engine (JD6)
  cannot evaluate keeps V as it is.
* Formula::Inherited -- F="Inh": the formula belongs to the master shape or style, V is this
  sheet's own result of it.
* Formula::NoFormula -- F="No Formula": explicitly without formula, V is a plain value.
`stale` says the formula changed and V is not its result yet; the engine clears it.  V holds
numbers as f64 and everything else as text: "Themed" (theme inheritance), "#RRGGBB" colours,
strings, NURBS(...) and POLYLINE(...) results, "1.#INF".
  • enum Value a cached value (V), numbers in internal units
    • Absent -- no V attribute
    • Num(f64) -- a number (lengths in inches, angles in radians ...)
    • Text(Sym) -- anything that is not a number, as written

impl Value

  • fn parse(text: &str, unit: Option<Unit>, strings: &mut Strings) -> Value V as the file writes it with its unit U: a finite number parses to Num, everything else stays text -- also every value of a STR or GUID cell and of an unknown unit ("007" is a serial number there, not 7)

  • fn num(self) -> Option<f64> the number, if the value is one

  • fn text(self) -> Option<Sym> the text, if the value is one

  • enum Formula the formula state of a cell (F)

    • Absent -- no F attribute: the value is the formula (a constant)
    • Inherited -- F="Inh": the formula is inherited, the value is this sheet's own
    • NoFormula -- F="No Formula": no formula
    • Expr(Sym) -- F holds an expression in the universal syntax

impl Formula

  • fn parse(text: &str, strings: &mut Strings) -> Formula F as the file writes it ("Inh", "No Formula" or an expression)

  • fn expr(self) -> Option<Sym> the expression, if F holds one

  • enum CellError the error state of a cell (E), after [MS-VSDX] Cell_Type

    • Dim -- #DIM!: a dimension out of range
    • DivZero -- #DIV/0!
    • Value -- #VALUE!: an operand of the wrong type
    • Ref -- #REF!: a reference to a cell that does not exist
    • Num -- #NUM!: an invalid number
    • NotAvailable -- #N/A: no value available
    • Name -- #NAME?: an unknown name

impl CellError

  • fn parse(text: &str) -> Option<CellError> the error of an E text (None for texts the crate does not know: keep them as Sym)

  • fn as_str(self) -> &'static str the text E holds

  • enum Origin where a cell's formula comes from

    • Local -- the sheet itself
    • Master -- the master shape (of an instance or of a subshape of one)
    • Style -- a style sheet (LineStyle, FillStyle, TextStyle and the styles they are based on)
    • Default -- nowhere: the cell has its built-in default
    • Deleted -- its row or section was deleted in the sheet or on the way to the master (Del="1")
  • struct Cell one cell as the file keeps it

    • name: Sym -- the cell name (N): "PinX", "X", "Value" ...
    • value: Value -- the cached value (V) in internal units
    • formula: Formula -- the formula state (F)
    • unit: Option<Unit> -- the unit it is shown in (U); None: no U attribute
    • error: Option<Sym> -- the error state (E) as written; CellError::parse types it
    • stale: bool -- the formula changed and the value is not its result yet

impl Cell

  • fn new(name: Sym) -> Cell a cell without value and formula attribute
  • fn constant(name: Sym, value: Value, unit: Option<Unit>) -> Cell a constant: the value is the formula
  • fn has_own_formula(&self) -> bool whether the cell keeps its own formula (not F="Inh")

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