pub struct Editor { /* private fields */ }Expand description
One editable circuit plus its undo and redo history.
Implementations§
Source§impl Editor
impl Editor
Sourcepub fn new(circuit: Circuit) -> Self
pub fn new(circuit: Circuit) -> Self
Wrap an already-parsed circuit. The document starts clean and with an empty history.
pub fn circuit(&self) -> &Circuit
Sourcepub fn is_dirty(&self) -> bool
pub fn is_dirty(&self) -> bool
Whether there are changes since the last Editor::mark_saved.
pub fn mark_saved(&mut self)
pub fn can_undo(&self) -> bool
pub fn can_redo(&self) -> bool
Sourcepub fn transact<T>(
&mut self,
edit: impl FnOnce(&mut Circuit) -> Result<T, EditError>,
) -> Result<T, EditError>
pub fn transact<T>( &mut self, edit: impl FnOnce(&mut Circuit) -> Result<T, EditError>, ) -> Result<T, EditError>
Apply edit to a copy of the circuit and commit it only if it returns
Ok. One call is one undo step.
Sourcepub fn redo(&mut self) -> bool
pub fn redo(&mut self) -> bool
Re-apply the last undone edit. False when there is nothing to redo.
pub fn add_part(&mut self, part: PartInstance) -> Result<(), EditError>
Sourcepub fn remove_part(&mut self, id: &str) -> Result<usize, EditError>
pub fn remove_part(&mut self, id: &str) -> Result<usize, EditError>
Remove a part and every wire attached to it. Returns the number of wires removed as well.
Sourcepub fn move_part(
&mut self,
id: &str,
left: f64,
top: f64,
) -> Result<(), EditError>
pub fn move_part( &mut self, id: &str, left: f64, top: f64, ) -> Result<(), EditError>
Move a part to a canvas position, snapped to the grid.
Sourcepub fn set_attr(
&mut self,
id: &str,
key: impl Into<String>,
value: Value,
) -> Result<(), EditError>
pub fn set_attr( &mut self, id: &str, key: impl Into<String>, value: Value, ) -> Result<(), EditError>
Set one attribute, creating it if needed.
Sourcepub fn connect(
&mut self,
from: PinRef,
to: PinRef,
color: Option<String>,
) -> Result<(), EditError>
pub fn connect( &mut self, from: PinRef, to: PinRef, color: Option<String>, ) -> Result<(), EditError>
Draw a wire. Duplicate pins and duplicate wires are refused.
pub fn disconnect(&mut self, index: usize) -> Result<(), EditError>
Sourcepub fn check(&self) -> Vec<Diagnostic>
pub fn check(&self) -> Vec<Diagnostic>
Structural diagnostics. Electrical checks live in litz-board, which
owns the runtime and the catalog.
Sourcepub fn validate(&self, registry: &Registry) -> Vec<Diagnostic>
pub fn validate(&self, registry: &Registry) -> Vec<Diagnostic>
Validate against a catalog: unknown part types, pins that do not exist, and connections the schema forbids.