Skip to main content

History

Struct History 

Source
pub struct History { /* private fields */ }
Expand description

The engine-owned mutable history.

Implementations§

Source§

impl History

Source

pub fn from_request_json(json: &str) -> Result<Self, String>

Load a whole history document (a saved part file parses as one). Rolls to the last feature. Ensures a features array exists.

Source

pub fn features(&self) -> &[Value]

The features slice (empty if none).

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn rollback(&self) -> usize

The rolled-to index, clamped to a valid feature (0 when empty).

Source

pub fn set_rollback(&mut self, index: usize)

Source

pub fn feature_type(&self, index: usize) -> Option<String>

Source

pub fn feature_id(&self, index: usize) -> Option<String>

Source

pub fn index_of(&self, id: &str) -> Option<usize>

Source

pub fn feature_params(&self, index: usize) -> Option<Value>

The inputParams document of the feature at index (for the dialog).

Source

pub fn fold_param_no_undo(&mut self, id: &str, key: &str, value: Value) -> bool

SOLVER write-back fold (the assembly pose-authority contract): set ONE inputParams key of the feature whose inputParams.id == id, WITHOUT an undo checkpoint and WITHOUT breaking edit coalescing — a solve write-back is the kernel adopting its own result, not a user edit, so it must never mint an undo entry (undoing a user action then re-running re-solves and re-folds anyway). Returns whether a feature matched.

Source

pub fn set_feature_params(&mut self, index: usize, params: Value)

Source

pub fn set_many_feature_params(&mut self, edits: &[(usize, Value)])

Replace the inputParams of MANY features as ONE mutation — Self::set_feature_params’s batch sibling, and the reason it exists: a packed BOM row rolls up N occurrences, so editing one cell writes N features. A set_feature_params loop would mint N undo entries (each keyed param:{index}, so none of them coalesce with each other), and the user would have to press undo N times to take back ONE edit.

Exactly ONE checkpoint covers the whole batch. The coalesce key names the SET of indices, so a run of edits to the SAME set (typing into one packed cell) still merges into a single entry, while switching to a different set starts a new one — the param:{index} rule, lifted to a group. Out-of-range indices are skipped; an empty batch is a no-op (no checkpoint, so a fan-out that matched nothing leaves no empty entry).

Source

pub fn push_feature(&mut self, feature: Value)

Source

pub fn push_features(&mut self, features: Vec<Value>)

Append MANY features as ONE mutation — the batch an import lane needs (EngineState::add_features). Distinct from a push_feature loop in the two ways that matter: exactly ONE undo checkpoint (an N-instance assembly import undoes in one step, not N), and the caller re-runs once instead of once per feature. No-op for an empty batch (no checkpoint, so an import that produced nothing leaves no empty undo entry).

Source

pub fn remove_feature(&mut self, index: usize)

Source

pub fn swap(&mut self, a: usize, b: usize)

Source

pub fn next_feature_id(&mut self, base: &str) -> String

Mint the id for a NEW feature: {base}{N} where base is the feature’s shortName and N is this history’s persistent GLOBAL counter, bumped by one on every mint (P.CUP.CU7, SS8). GLOBAL across all feature types, MONOTONIC, and NEVER reused — a delete does not free a number and undo does not rewind the counter — and it persists across save/load, so two features can never receive the same id over the document’s whole lifetime.

Source

pub fn prefix_request(&self) -> Value

The stopAtId-truncated request that stops AFTER the rolled-to feature — the roll-to-step request the pipeline runs. Empty history → empty request.

Source

pub fn listing_json(&self) -> String

The tree listing for the UI: { step, features: [{index, type, id}] }.

Source

pub fn request_json(&self) -> String

The whole request document (for persistence / debugging), with the persistent global feature counter folded back in under "featureCounter" so it round-trips through save/load (the twin of Self::from_request_json, which lifts it back out). Written only when non-zero, so a document that has never minted a feature persists byte-for-byte as before (mirrors the metadata field’s “un-annotated model persists unchanged” convention).

Source

pub fn request_json_without_parts_library(&self) -> String

The document WITHOUT the parts-library block — for the kernel round trips that never read it. The assembly pose fold (assembly_apply_document_json) only rewrites the assembly block and per-feature inputParams, so handing it the library would serialize, parse and re-serialize megabytes of part payload on every edit for nothing. Self::request_json is the SAVE door and still carries it.

Source

pub fn adopt_folded_request(&mut self, json: &str) -> Result<(), String>

ADOPT a kernel-folded document (the assembly pose-authority write-back: assembly_apply_document_json returned this document with the solved assembly block + poses/isFixed folded onto the owning features). Replaces the request WHOLESALE while keeping the rollback index (clamped), the undo/redo stacks, and the live feature counter — a solver write-back is not a user edit, so no undo checkpoint is pushed (the constraint edit that triggered the solve lives in the kernel session’s state, outside the engine undo lane — flagged for the integrator).

Source

pub fn can_undo(&self) -> bool

Whether an undo step is available (for enabling the toolbar button).

Source

pub fn can_redo(&self) -> bool

Whether a redo step is available.

Source

pub fn undo(&mut self) -> bool

Undo the last model mutation: push the current state onto the redo stack and restore the previous document + rolled-to step. Returns whether it changed anything (false when the undo stack is empty).

Source

pub fn redo(&mut self) -> bool

Redo the last undone model mutation (symmetric with Self::undo).

Source§

impl History

Source

pub fn adopt_document(&mut self, document_json: &str) -> Result<(), String>

ADOPT a whole replacement document — the assembly FOLD’s write-back lane (assembly_apply_document_json returns the document with the solved assembly block + poses/isFixed folded into the features; the engine adopts it before persisting or re-running — the pose-authority contract).

checkpoint chooses the undo semantics: a USER constraint mutation records an undo snapshot (so constraint edits stay undoable like any model edit); the silent post-run pose fold passes false (solver write-back is not a user edit — undoing the user’s LAST edit must not strand an extra fold step in between).

A stray featureCounter in the adopted document is stripped (the in-memory counter stays authoritative — request_json re-folds it on serialize, exactly like from_request_json lifts it on load). The rollback index is preserved (the fold never changes the feature count).

Source

pub fn adopt_document_checkpointed( &mut self, document_json: &str, ) -> Result<(), String>

Same adoption with an undo snapshot recorded FIRST (never coalesced) — the user-mutation twin of Self::adopt_document.

Source

pub fn set_parts_library(&mut self, library: Value)

Replace the document’s partsLibrary block (the assemblies parts library, spec §2.1) — the caller feeds brep_kernel::parts_library_json() here (never an echo of a loaded block), so SAVE serializes the kernel store with its heals and GC. An empty map clears the field, so a non-assembly document serializes byte-identically to before.

The block is held in the parts_library FIELD rather than on self.request; Self::request_json folds it back into the saved document. The on-disk shape is unchanged.

Source

pub fn set_parts_library_edited( &mut self, library: Value, coalesce_key: Option<&str>, )

Replace the partsLibrary block as a USER EDIT: one undo checkpoint, and the mirror flag CLEARED so the next run ships the block to the runner instead of assuming the kernel store already agrees.

Self::set_parts_library is the other door and means the opposite — “this block came OUT of the kernel store” — so it must not be reused here: a part-attribute edit is authored on this side and the runner has never seen it. coalesce_key follows the param:{index} rule so a run of keystrokes into one attribute is one undo entry.

Source

pub fn parts_library_mirrors_store(&self) -> bool

Whether the partsLibrary block currently mirrors the kernel store (see parts_library_mirrors_store).

Source

pub fn parts_library(&self) -> &Value

The partsLibrary block (Value::Null when the document has none).

Source

pub fn assembly_block(&self) -> Option<&Value>

The document’s assembly block ({constraints, idCounter}), if any.

Source

pub fn wire_harness_block(&self) -> Option<&Value>

The document’s wireHarness block ({connections, idCounter, buildBundles}), if any.

Source

pub fn set_wire_harness_block(&mut self, block: Option<Value>)

Replace (or, with None, remove) the wireHarness block. A USER edit: snapshotted for undo, never coalesced — each add / edit / remove of a connection is its own undo step, like a feature add or delete.

Source§

impl History

Source

pub fn pmi_block(&self) -> Option<&Value>

The document’s pmi block ({views, idCounter}), if any.

Source

pub fn set_pmi_block( &mut self, block: Option<Value>, coalesce_key: Option<&str>, )

Replace (or, with None, remove) the pmi block as a USER edit: snapshotted for undo. coalesce_key groups a run of rapid same-target edits (a label drag: pmi:label:{id}) into ONE undo entry; None makes the edit its own step (a view capture, an annotation add / edit / delete).

Source

pub fn set_pmi_block_no_undo(&mut self, block: Option<Value>)

Replace the pmi block WITHOUT an undo checkpoint — for a write that belongs to the checkpoint just taken (an import lifting a file’s PMI beside the feature it added, so one undo removes both).

Source

pub fn break_coalescing(&mut self)

End a coalescing run (a label drag released): the next edit with the same key starts a fresh undo entry.

Source§

impl History

Source

pub fn part_attributes_block(&self) -> Option<&Value>

The document’s own partAttributes record, if any.

Source

pub fn set_part_attributes_block( &mut self, block: Option<Value>, coalesce_key: Option<&str>, )

Replace (or, with None, remove) the document’s own partAttributes record as a USER edit: snapshotted for undo. coalesce_key groups a run of edits to ONE field (a typing run in the Properties dialog) into a single undo entry, exactly as the PMI block’s does.

Source§

impl History

Source

pub fn expressions(&self) -> String

The history document’s expressions source string (empty when absent or stored as null). The panel’s editor binds to this.

Source

pub fn set_expressions(&mut self, expressions: &str)

Replace the expressions source string. Snapshotted for undo, coalescing a run of keystroke edits into ONE undo entry (like a slider drag) via the shared "expressions" coalesce key, so a distinct add/edit/roll starts a fresh entry. A no-op re-set (same text) still records under the same key.

Source

pub fn configurator(&self) -> Value

The configurator object (typed named inputs), or {} when absent — read-only for the panel’s display (deeper configurator editing deferred).

Source§

impl History

Source

pub fn feature_persistent_data(&self, index: usize) -> Option<Value>

The persistentData document of the feature at index (None if the feature or the field is absent) — the read twin of Self::feature_params.

Source

pub fn set_feature_persistent_field( &mut self, index: usize, key: &str, value: Value, )

Set a single key inside the feature-at-index’s persistentData object, creating (or replacing a non-object) persistentData as needed. Snapshotted for undo (a structural edit — never coalesced), like an add/delete.

Source

pub fn set_feature_persistent_field_coalesced( &mut self, index: usize, key: &str, value: Value, coalesce_key: Option<&str>, )

Self::set_feature_persistent_field with an optional COALESCE key: a run of same-key writes (a gizmo drag moving a spline anchor, frame after frame) records ONE undo entry, exactly as a slider drag on a param does.

Trait Implementations§

Source§

impl Clone for History

Source§

fn clone(&self) -> History

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for History

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for History

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>