Skip to main content

Engine

Struct Engine 

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

The Dotloom engine.

Implementations§

Source§

impl Engine

Source

pub fn begin_drag(&mut self, spec: DragSpec) -> Result<(), EngineError>

Start dragging.

Source

pub fn is_dragging(&self) -> bool

Whether a drag is active.

Source

pub fn drag_to( &mut self, to: Point, ) -> Result<(DragPreview, SceneDelta), EngineError>

Update the drag to a pointer position. Returns the preview status and a preview scene delta (empty when the position is rejected).

Source

pub fn end_drag( &mut self, commit: bool, ) -> Result<Option<CommitReport>, EngineError>

Finish the drag: commit the last valid preview as one history entry, or cancel and restore the committed scene.

Source§

impl Engine

Source

pub fn new(options: EngineOptions) -> Self

Engine with an empty document.

Source

pub fn document(&self) -> &Document

The committed document (read-only).

Source

pub fn revision(&self) -> u64

Current revision (increments on every commit, undo and redo).

Source

pub fn registry(&self) -> &Registry

Type registry.

Source

pub fn load(&mut self, doc: Document) -> Result<u64, EngineError>

Replace the document. Entity type migrations of registered plugins are applied; the document is validated; history is cleared.

Source

pub fn register_type( &mut self, def: EntityTypeDef, plugin: &str, ) -> Result<(), EngineError>

Register a plugin entity type.

Source

pub fn unregister_type(&mut self, t: &TypeId) -> Result<(), EngineError>

Remove a plugin entity type (its entities become read-only, data is kept).

Source

pub fn set_type_enabled( &mut self, t: &TypeId, enabled: bool, ) -> Result<(), EngineError>

Enable or disable a plugin entity type.

Source

pub fn reserve_ids(&mut self, n: usize) -> Vec<u64>

Reserve fresh IDs for use in the next transactions (e.g. a tool that creates a line and a constraint on it in one transaction).

Source

pub fn apply( &mut self, tx: Transaction, opts: ApplyOptions, ) -> Result<CommitReport, EngineError>

Apply a transaction synchronously.

Source

pub fn begin_apply( &mut self, tx: Transaction, opts: ApplyOptions, ) -> Result<u64, EngineError>

Start a transaction whose solve runs in budgeted steps (Engine::step_pending). Returns the pending request ID.

Source

pub fn has_pending(&self) -> bool

Whether a pending commit exists.

Source

pub fn step_pending(&mut self, budget: u32) -> Result<PendingState, EngineError>

Run the pending commit for at most budget solver iterations.

Source

pub fn cancel_pending(&mut self) -> bool

Cancel the pending commit (the document is unchanged).

Source

pub fn undo(&mut self, opts: ApplyOptions) -> Result<u64, EngineError>

Undo the last commit (applies the stored before-state; no solving).

Source

pub fn redo(&mut self, opts: ApplyOptions) -> Result<u64, EngineError>

Redo the last undone commit.

Source

pub fn can_undo(&self) -> bool

Whether undo is possible.

Source

pub fn can_redo(&self) -> bool

Whether redo is possible.

Source

pub fn history_bytes(&self) -> usize

History memory estimate in bytes.

Source

pub fn take_events(&mut self) -> Vec<Event>

Drain pending events.

Source

pub fn selection(&self) -> Vec<EntityId>

Current selection.

Source

pub fn set_selection(&mut self, ids: &[EntityId])

Replace the selection (unknown IDs are ignored).

Source

pub fn evaluate(&mut self, id: EntityId) -> Option<Evaluated>

Evaluation of an entity (anchors, drawables) from the committed document.

Source

pub fn constraints_of(&self, id: EntityId) -> Vec<ConstraintId>

Constraints that reference an entity.

Source

pub fn analyze(&self) -> (Status, Vec<DiagnosticReport>)

Analyse every constraint of the document (status, DOF, conflicts) without changing anything.

Source

pub fn verify(&self) -> Vec<(String, f64, f64)>

Check every enabled hard rule (document constraints and plugin templates) against the stored values with the independent evaluator, without solving. Returns violations as (what, residual, tolerance).

Source

pub fn params_of(&self, id: EntityId) -> BTreeMap<String, f64>

Parameter values of an entity (name, value).

Source§

impl Engine

Source

pub fn hit_test(&mut self, point: Point, radius: f64) -> Vec<Hit>

Entities under point within radius, nearest first (ties: topmost first).

Source

pub fn select_in_rect(&mut self, rect: Aabb, mode: SelectMode) -> Vec<EntityId>

Area selection.

Source

pub fn snap(&mut self, q: &SnapQuery) -> Option<Snap>

Snap a point. Hysteresis (previous) limits flicker between candidates: the previous snap is kept within 1.5 × radius unless a better kind appears or a same-kind candidate is closer by more than [HYSTERESIS] × radius.

The result is a proposal: committing it still goes through the solver and independent checks, so a snap can never commit a hard-rule violation.

Source§

impl Engine

Source

pub fn take_scene_delta(&mut self) -> SceneDelta

Changes since the last call (or the whole scene after load/reset).

Source

pub fn full_scene(&mut self) -> SceneDelta

The complete scene.

Trait Implementations§

Source§

impl Debug for Engine

Source§

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

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

impl Default for Engine

Source§

fn default() -> Self

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

impl DocView for Engine

Source§

fn entity(&self, id: EntityId) -> Option<&Entity>

Entity by ID.
Source§

fn constraint(&self, id: ConstraintId) -> Option<&Constraint>

Constraint by ID.
Source§

fn layer(&self, id: LayerId) -> Option<&Layer>

Layer by ID.
Source§

fn group(&self, id: GroupId) -> Option<&Group>

Group by ID.
Source§

fn settings(&self) -> &Settings

Settings.

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<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> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.