pub struct History { /* private fields */ }Expand description
The engine-owned mutable history.
Implementations§
Source§impl History
impl History
Sourcepub fn from_request_json(json: &str) -> Result<Self, String>
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.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn rollback(&self) -> usize
pub fn rollback(&self) -> usize
The rolled-to index, clamped to a valid feature (0 when empty).
pub fn set_rollback(&mut self, index: usize)
pub fn feature_type(&self, index: usize) -> Option<String>
pub fn feature_id(&self, index: usize) -> Option<String>
pub fn index_of(&self, id: &str) -> Option<usize>
Sourcepub fn feature_params(&self, index: usize) -> Option<Value>
pub fn feature_params(&self, index: usize) -> Option<Value>
The inputParams document of the feature at index (for the dialog).
Sourcepub fn fold_param_no_undo(&mut self, id: &str, key: &str, value: Value) -> bool
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.
pub fn set_feature_params(&mut self, index: usize, params: Value)
Sourcepub fn set_many_feature_params(&mut self, edits: &[(usize, Value)])
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).
pub fn push_feature(&mut self, feature: Value)
Sourcepub fn push_features(&mut self, features: Vec<Value>)
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).
pub fn remove_feature(&mut self, index: usize)
pub fn swap(&mut self, a: usize, b: usize)
Sourcepub fn next_feature_id(&mut self, base: &str) -> String
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.CU → P.CU7, S → S8). 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.
Sourcepub fn prefix_request(&self) -> Value
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.
Sourcepub fn listing_json(&self) -> String
pub fn listing_json(&self) -> String
The tree listing for the UI: { step, features: [{index, type, id}] }.
Sourcepub fn request_json(&self) -> String
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).
Sourcepub fn request_json_without_parts_library(&self) -> String
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.
Sourcepub fn adopt_folded_request(&mut self, json: &str) -> Result<(), String>
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).
Sourcepub fn can_undo(&self) -> bool
pub fn can_undo(&self) -> bool
Whether an undo step is available (for enabling the toolbar button).
Sourcepub fn undo(&mut self) -> bool
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).
Sourcepub fn redo(&mut self) -> bool
pub fn redo(&mut self) -> bool
Redo the last undone model mutation (symmetric with Self::undo).
Source§impl History
impl History
Sourcepub fn adopt_document(&mut self, document_json: &str) -> Result<(), String>
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).
Sourcepub fn adopt_document_checkpointed(
&mut self,
document_json: &str,
) -> Result<(), String>
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.
Sourcepub fn set_parts_library(&mut self, library: Value)
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.
Sourcepub fn set_parts_library_edited(
&mut self,
library: Value,
coalesce_key: Option<&str>,
)
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.
Sourcepub fn parts_library_mirrors_store(&self) -> bool
pub fn parts_library_mirrors_store(&self) -> bool
Whether the partsLibrary block currently mirrors the kernel store
(see parts_library_mirrors_store).
Sourcepub fn parts_library(&self) -> &Value
pub fn parts_library(&self) -> &Value
The partsLibrary block (Value::Null when the document has none).
Sourcepub fn assembly_block(&self) -> Option<&Value>
pub fn assembly_block(&self) -> Option<&Value>
The document’s assembly block ({constraints, idCounter}), if any.
Sourcepub fn wire_harness_block(&self) -> Option<&Value>
pub fn wire_harness_block(&self) -> Option<&Value>
The document’s wireHarness block ({connections, idCounter, buildBundles}), if any.
Sourcepub fn set_wire_harness_block(&mut self, block: Option<Value>)
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
impl History
Sourcepub fn pmi_block(&self) -> Option<&Value>
pub fn pmi_block(&self) -> Option<&Value>
The document’s pmi block ({views, idCounter}), if any.
Sourcepub fn set_pmi_block(
&mut self,
block: Option<Value>,
coalesce_key: Option<&str>,
)
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).
Sourcepub fn set_pmi_block_no_undo(&mut self, block: Option<Value>)
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).
Sourcepub fn break_coalescing(&mut self)
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
impl History
Sourcepub fn part_attributes_block(&self) -> Option<&Value>
pub fn part_attributes_block(&self) -> Option<&Value>
The document’s own partAttributes record, if any.
Sourcepub fn set_part_attributes_block(
&mut self,
block: Option<Value>,
coalesce_key: Option<&str>,
)
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
impl History
Sourcepub fn expressions(&self) -> String
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.
Sourcepub fn set_expressions(&mut self, expressions: &str)
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.
Sourcepub fn configurator(&self) -> Value
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
impl History
Sourcepub fn feature_persistent_data(&self, index: usize) -> Option<Value>
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.
Sourcepub fn set_feature_persistent_field(
&mut self,
index: usize,
key: &str,
value: Value,
)
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.
Sourcepub fn set_feature_persistent_field_coalesced(
&mut self,
index: usize,
key: &str,
value: Value,
coalesce_key: Option<&str>,
)
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§
Auto Trait Implementations§
impl !Send for History
impl !Sync for History
impl Freeze for History
impl RefUnwindSafe for History
impl Unpin for History
impl UnsafeUnpin for History
impl UnwindSafe for History
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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