use crate::controls::ArcballControls;
use crate::history::History;
use crate::pick::{self, PickOptions};
use crate::scene::RenderScene;
use crate::style::{Emphasis, RenderSettings};
use crate::view::ViewCamera;
use crate::widgets::{gizmo_camera, WidgetOverlay, WidgetRegistry};
use brep_kernel::HistoryRequest;
use std::collections::HashMap;
#[derive(Clone)]
pub(crate) struct DialogHover {
pub(crate) owner: &'static str,
pub(crate) row: String,
pub(crate) candidate: Option<pick::PickCandidate>,
}
pub struct EngineState {
pub scene: RenderScene,
pub context_scene: RenderScene,
pub(crate) context_selected: Option<crate::pick::PickCandidate>,
pub(crate) context_hovered: Option<crate::pick::PickCandidate>,
pub(crate) context_pick_lit: Vec<String>,
pub(crate) context_display: crate::engine_state::context_pick::ContextDisplay,
pub camera: ViewCamera,
pub controls: ArcballControls,
pub settings: RenderSettings,
pub emphasis: Emphasis,
pub widgets: WidgetRegistry,
pub history: History,
interference_sessions: std::collections::BTreeMap<String, interference::InterferenceCursor>,
interference_sequence: u64,
illustration_snapshot: Option<illustration::IllustrationSnapshot>,
geometry_diagnostics: std::collections::BTreeMap<String, serde_json::Value>,
staged_feature: Option<batch::StagedFeature>,
busy_refused_seen: u64,
history_report: String,
pub metadata: crate::metadata::MetadataStore,
document_thumbnail: std::cell::RefCell<Option<(u64, serde_json::Value)>>,
thumbnail_cache: std::cell::RefCell<Option<(Vec<u64>, serde_json::Value)>>,
pub settings_generation: u64,
pub dirty: bool,
pub ref_select: Option<RefSelectState>,
pub(crate) replace_repair_pick: Option<(String, String, String)>,
pub selection_filter: SelectionFilter,
pub transform_gizmo: TransformArm,
pub component_move: ComponentMoveArm,
sketch_edit: Option<SketchEdit>,
sketch3d_edit: Option<Sketch3dEdit>,
pub(crate) sketch3d_overlay_wpp: f64,
sketch_camera_locked: bool,
sketch_list_hover_active: bool,
notices: Vec<String>,
graded_notices: Vec<(NoticeSeverity, String)>,
hidden_sketches: std::collections::HashSet<String>,
shown_sketch_ids: Vec<String>,
shown_board_ids: Vec<String>,
board_built_from: Option<brep_ecad_core::board::Board>,
board_pin_nets: std::collections::BTreeMap<(brep_ecad_core::Uuid, String), String>,
board_build: board_geometry::BoardBuild,
board_displays: Vec<crate::scene::SolidDisplay>,
construction_frames: Vec<(String, brep_kernel::Frame)>,
sketch_profiles: Vec<(String, brep_kernel::SketchProfile)>,
sketch_paths: Vec<(String, Vec<brep_kernel::NurbsCurve>)>,
sketch_points: Vec<(String, brep_kernel::ScenePoint)>,
sketch_axes: Vec<(String, brep_kernel::Axis)>,
wire_harness_report: Option<brep_kernel::WireHarnessReport>,
ports_report: Option<brep_kernel::PortsReport>,
pub(crate) pmi_report: Option<brep_kernel::PmiReport>,
pub(crate) pmi_active_view: Option<String>,
pub(crate) pmi_open_annotation: Option<String>,
pub(crate) pmi_open_view: Option<String>,
pub(crate) pmi_selected_annotation: Option<String>,
pub(crate) pmi_selected_view: Option<String>,
pub(crate) pmi_dialog_opens: u64,
pub(crate) pmi_modeling: Option<pmi_ops::PmiModelingSnapshot>,
pub(crate) pmi_explode_originals: std::collections::HashMap<String, crate::scene::SolidDisplay>,
pub(crate) explode_playback: exploded_ops::ExplodePlayback,
pub(crate) simulation_play: Option<simulation_play::SimulationPlayback>,
pub(crate) pmi_section_hidden: Vec<String>,
pub(crate) pmi_unposed_visibility: u64,
pub(crate) pmi_state_cache: std::cell::RefCell<Option<(u64, std::rc::Rc<brep_kernel::PmiState>)>>,
pub(crate) pmi_balloon_stale: Option<String>,
pub(crate) pmi_overlay_key: Option<(f64, [f64; 3])>,
pub(crate) pmi_hovered: Option<String>,
pub(crate) pmi_label_hover_active: bool,
pub(crate) sheet_open: Option<String>,
pub(crate) sheet_open_object: Option<String>,
pub(crate) sheet_object_opens: u64,
pub(crate) sheet_selected_object: Option<String>,
pub(crate) sheet_cache: Option<sheet_ops::SheetCache>,
pub(crate) sheet_lines: sheet_ops::SheetLinesWork,
pub(crate) document_name: String,
spline_overlay_key: Option<(String, Option<usize>, u64)>,
pub cam: cam_ops::CamGeneration,
component_ports_visible: bool,
spline_edit_feature: Option<String>,
spline_anchor_picked: Option<usize>,
cage_edit_feature: Option<String>,
cage_overlay_key: Option<(String, Vec<usize>, u64)>,
hidden_datums: std::collections::HashSet<String>,
shown_datum_names: Vec<String>,
pub(crate) runner: Box<dyn crate::runner::HistoryRunner>,
plugins: plugins::Plugins,
run_generation: u64,
applied_generation: u64,
run_progress: Option<crate::runner::RunProgress>,
cancelled_run: Option<String>,
expression_preview: Option<ExpressionPreview>,
runs_replied: u64,
superseded_displays: HashMap<String, crate::scene::SolidDisplay>,
pending_fit: bool,
instructions_wizard_pending: bool,
instructions_views_pending: bool,
pub(crate) instructions_insertion: Option<instructions_ops::Insertion>,
pub(crate) provenance: std::collections::HashMap<String, String>,
pub(crate) entity_origin: std::collections::HashMap<String, String>,
pub(crate) info_cache: std::collections::HashMap<String, String>,
pub(crate) pending_query: std::collections::HashMap<u64, String>,
pub(crate) next_query_id: u64,
pub(crate) pending_mesh_imports: std::collections::HashMap<u64, MeshImportDestination>,
pub(crate) mesh_preview_results: std::collections::VecDeque<crate::runner::MeshImportReply>,
pub(crate) next_mesh_import_id: u64,
pub(crate) pending_topology: std::collections::HashSet<u64>,
pub(crate) topology_asked: std::collections::HashSet<u32>,
pub(crate) next_topology_id: u64,
pub(crate) assembly_sync: Option<crate::pipeline::AssemblySync>,
pub(crate) assembly_components: Vec<crate::pipeline::ComponentSnapshot>,
pub(crate) assembly_session_generation: Option<u64>,
pub(crate) assembly_session_serial: u64,
pub(crate) session_transfer: bool,
pub(crate) session_imports: u64,
pub(crate) session_replays: u64,
pub(crate) replace_pending: Option<replace_component::PendingReplace>,
pub(crate) last_replace_report: Option<serde_json::Value>,
pub(crate) consumed_names: std::collections::HashSet<String>,
pub(crate) library_resync: bool,
pub(crate) sketch_links_released: bool,
pub(crate) constraint_overlays: Vec<crate::constraint_overlays::ConstraintOverlay>,
pub(crate) constraint_drag: Option<ConstraintDrag>,
constraint_overlay_wpp: f64,
freedom_glyph_key: Option<String>,
freedom_glyph_wpp: f64,
pub(crate) feature_dim_overlay_wpp: f64,
pub(crate) sketch_overlay_wpp: f64,
constraint_hovered: Option<String>,
constraint_label_hover_active: bool,
scene_tree_hovered: Option<pick::PickCandidate>,
scene_tree_hover_active: bool,
dialog_hovered: Option<DialogHover>,
dialog_hover_active: bool,
selected_constraint: Option<String>,
selected_feature: Option<(String, selection_ux::FeatureSelection)>,
pub(crate) constraint_opens: u64,
pub(crate) pending_step_assembly: Option<brep_kernel::StepAssembly>,
pub(crate) pending_step_probes: std::collections::HashSet<u64>,
pub(crate) step_probe_results: std::collections::VecDeque<(u64, StepProbeOutcome)>,
pub(crate) next_step_probe_id: u64,
}
#[derive(Debug, Clone, PartialEq)]
pub enum StepProbeOutcome {
Structure(model_io::StepAssemblyProbe),
Flat,
Failed(String),
}
#[derive(Debug, Clone)]
pub struct ConstraintDrag {
pub id: String,
pub field: &'static str,
pub params: serde_json::Value,
pub preview: f64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum RefSelectTarget {
#[default]
Feature,
AssemblyConstraint,
SplineAnchor { index: usize },
Pmi,
PortPoint { field: ports_ops::PortRefField },
Sheet,
Cam,
Instructions { field: InstructionsRefField },
Simulation,
ReplaceRepair,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InstructionsRefField {
Arrow(usize),
Callout(usize),
}
#[derive(Debug, Clone, Default)]
pub struct RefSelectState {
pub feature_id: String,
pub path: Vec<String>,
pub label: String,
pub filter: Vec<String>,
pub multiple: bool,
pub names: Vec<String>,
pub restore_index: usize,
pub target: RefSelectTarget,
pub picks: usize,
pub claimed: bool,
pub finish_requested: bool,
}
impl Default for EngineState {
fn default() -> Self {
Self {
scene: RenderScene::new(),
context_scene: RenderScene::new(),
context_selected: None,
context_hovered: None,
context_pick_lit: Vec::new(),
context_display: Default::default(),
camera: ViewCamera::default(),
controls: ArcballControls::new(),
settings: RenderSettings::default(),
emphasis: Emphasis::default(),
widgets: WidgetRegistry::new(),
history: History::default(),
history_report: String::new(),
metadata: crate::metadata::MetadataStore::new(),
document_thumbnail: std::cell::RefCell::new(None),
thumbnail_cache: std::cell::RefCell::new(None),
settings_generation: 1,
dirty: true,
ref_select: None,
replace_repair_pick: None,
selection_filter: SelectionFilter::default(),
transform_gizmo: TransformArm::default(),
component_move: ComponentMoveArm::default(),
sketch_edit: None,
sketch3d_edit: None,
sketch3d_overlay_wpp: 0.0,
sketch_camera_locked: true,
sketch_list_hover_active: false,
notices: Vec::new(),
graded_notices: Vec::new(),
hidden_sketches: std::collections::HashSet::new(),
shown_sketch_ids: Vec::new(),
shown_board_ids: Vec::new(),
board_built_from: None,
board_pin_nets: Default::default(),
board_build: board_geometry::BoardBuild::default(),
board_displays: Vec::new(),
construction_frames: Vec::new(),
sketch_profiles: Vec::new(),
sketch_paths: Vec::new(),
sketch_points: Vec::new(),
sketch_axes: Vec::new(),
wire_harness_report: None,
ports_report: None,
sheet_open: None,
sheet_open_object: None,
sheet_object_opens: 0,
sheet_selected_object: None,
sheet_cache: None,
sheet_lines: Default::default(),
document_name: String::new(),
pmi_report: None,
pmi_active_view: None,
pmi_open_annotation: None,
pmi_open_view: None,
pmi_selected_annotation: None,
pmi_selected_view: None,
pmi_dialog_opens: 0,
pmi_modeling: None,
pmi_explode_originals: std::collections::HashMap::new(),
explode_playback: Default::default(),
simulation_play: None,
pmi_section_hidden: Vec::new(),
pmi_unposed_visibility: 0,
pmi_state_cache: Default::default(),
pmi_balloon_stale: None,
pmi_overlay_key: None,
pmi_hovered: None,
pmi_label_hover_active: false,
spline_overlay_key: None,
cam: cam_ops::CamGeneration::default(),
component_ports_visible: false,
spline_edit_feature: None,
spline_anchor_picked: None,
cage_edit_feature: None,
cage_overlay_key: None,
hidden_datums: std::collections::HashSet::new(),
shown_datum_names: Vec::new(),
runner: Box::new(crate::runner::InlineRunner::new()),
plugins: plugins::Plugins::default(),
interference_sessions: Default::default(),
interference_sequence: 0,
illustration_snapshot: None,
geometry_diagnostics: Default::default(),
staged_feature: None,
busy_refused_seen: 0,
run_generation: 0,
applied_generation: 0,
run_progress: None,
cancelled_run: None,
expression_preview: None,
runs_replied: 0,
superseded_displays: HashMap::new(),
pending_fit: false,
instructions_wizard_pending: false,
instructions_views_pending: false,
instructions_insertion: None,
provenance: std::collections::HashMap::new(),
entity_origin: std::collections::HashMap::new(),
info_cache: std::collections::HashMap::new(),
pending_query: std::collections::HashMap::new(),
next_query_id: 0,
pending_mesh_imports: std::collections::HashMap::new(),
mesh_preview_results: std::collections::VecDeque::new(),
next_mesh_import_id: 0,
pending_topology: std::collections::HashSet::new(),
topology_asked: std::collections::HashSet::new(),
next_topology_id: 0,
assembly_components: Vec::new(),
assembly_sync: None,
assembly_session_generation: None,
assembly_session_serial: 0,
session_transfer: true,
session_imports: 0,
session_replays: 0,
replace_pending: None,
last_replace_report: None,
consumed_names: std::collections::HashSet::new(),
library_resync: false,
sketch_links_released: false,
constraint_overlays: Vec::new(),
constraint_drag: None,
constraint_overlay_wpp: 0.0,
freedom_glyph_key: None,
freedom_glyph_wpp: 0.0,
feature_dim_overlay_wpp: 0.0,
sketch_overlay_wpp: 0.0,
constraint_hovered: None,
constraint_label_hover_active: false,
scene_tree_hovered: None,
scene_tree_hover_active: false,
dialog_hovered: None,
dialog_hover_active: false,
selected_constraint: None,
selected_feature: None,
constraint_opens: 0,
pending_step_assembly: None,
pending_step_probes: std::collections::HashSet::new(),
step_probe_results: std::collections::VecDeque::new(),
next_step_probe_id: 1,
}
}
}
impl EngineState {
pub fn new() -> Self {
Self::default()
}
fn pick_options(&self) -> PickOptions {
PickOptions {
double_sided: self.settings.pick_double_sided,
..PickOptions::default()
}
}
}
pub(crate) fn overlay_wpp_stale(baked: f64, now: f64) -> bool {
baked > 0.0 && (now - baked).abs() > baked * 0.005
}
mod assembly_ops;
mod context_pick;
mod assembly_overlay;
pub mod replace_component;
mod bom;
mod camera_widgets;
mod board_geometry;
mod committed_sketches;
mod component_move;
mod assembly_flip;
mod components;
mod construction_datums;
mod expressions;
pub use expressions::ExpressionPreview;
mod feature_dims;
mod interference;
mod batch;
mod plugins;
mod illustration;
mod history_ops;
mod model_io;
mod plane_pick;
mod scene_query;
mod selection_filter;
mod selection_ux;
mod sketch_edit_ops;
mod sketch_input;
mod sketch_mode;
mod sketch3d_mode;
pub use sketch3d_mode::{Sketch3dCursorHit, Sketch3dEdit};
mod sketch_panel;
mod transform_gizmo;
mod wire_harness_ops;
mod ports_ops;
pub use ports_ops::PortRefField;
pub use selection_ux::RefSelectField;
mod wire_bom;
mod pmi_ops;
mod pmi_section;
mod exploded_ops;
pub use exploded_ops::{ExplodePlayback, ExplodeStep, ExplodedView};
mod instructions_ops;
pub use instructions_ops::{Insertion, PlayTo};
mod simulation_ops;
pub use simulation_ops::MotorMate;
mod simulation_play;
pub use simulation_play::{BakedFrame, SimulationPlayback};
mod simulation_player;
pub use simulation_player::assembly_signature;
mod simulation_refs;
mod instructions_motion;
pub use instructions_motion::PublishedMotion;
mod instructions_export;
pub use instructions_export::IMAGE_PX as INSTRUCTIONS_IMAGE_PX;
pub use instructions_export::{TOPOLOGY_WAIT, InstructionsPdfExport};
pub mod cam_ops;
pub use pmi_ops::{pmi_view_params, pmi_view_schema, world_vertex_ref, PmiModelingSnapshot, PmiViewPatch};
mod sheet_ops;
pub(crate) mod pmi_overlay;
pub use pmi_overlay::PmiLabel;
mod spline_edit;
mod cage_edit;
pub use assembly_ops::{document_signature, nested_fixed_state, ComponentInsert};
pub use board_geometry::{
default_color as board_default_color, BoardBuild, BOARD_SOLID_PREFIX, SUBSTRATE_SOLID,
VIAS_SOLID,
};
pub use bom::{OCCURRENCE_ATTRIBUTES, PART_ATTRIBUTES};
pub use component_move::{ComponentMoveArm, TypedMove};
pub use components::ComponentInfo;
pub use interference::{ClearancePair, InterferencePair, InterferenceReport, INTERFERENCE_OVERLAY_GROUP};
pub use model_io::{
EmbeddedOnly, PartSink, StepAssemblyImport, StepAssemblyProbe, StepAssemblyReport,
};
pub use selection_filter::SelectionFilter;
pub use sketch_mode::{SketchDrag, SketchEdit};
pub use sketch_panel::{NoticeSeverity, SketchConstraintAction, SketchEntityRow};
pub use wire_harness_ops::ConnectionPatch;
pub use wire_bom::{WireBomLine, WireLengthState};
pub use spline_edit::SplineAnchorRow;
pub use cage_edit::{CageArm, CageSelect, CageSummary, CAGE_PICK_RADIUS_PX};
pub use transform_gizmo::{GizmoMode, TransformArm};
pub(crate) use transform_gizmo::rotate_euler_xyz_f64;
#[derive(Clone, Copy, PartialEq, Eq)]
pub(crate) enum MeshImportDestination {
Document,
Preview,
}