mirror of https://codeberg.org/topola/topola.git
refactor(egui): add empty skeleton for interactions
This commit is contained in:
parent
a9b72334f7
commit
74ef5e356f
|
|
@ -45,6 +45,12 @@ pub trait GetObstacles {
|
||||||
fn obstacles(&self) -> &[PrimitiveIndex];
|
fn obstacles(&self) -> &[PrimitiveIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum InvokerStatus {
|
||||||
|
Running,
|
||||||
|
Finished(String),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug, Clone)]
|
#[derive(Error, Debug, Clone)]
|
||||||
pub enum InvokerError {
|
pub enum InvokerError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
|
@ -53,12 +59,6 @@ pub enum InvokerError {
|
||||||
Autorouter(#[from] AutorouterError),
|
Autorouter(#[from] AutorouterError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum InvokerStatus {
|
|
||||||
Running,
|
|
||||||
Finished(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryInto<()> for InvokerStatus {
|
impl TryInto<()> for InvokerStatus {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
fn try_into(self) -> Result<(), ()> {
|
fn try_into(self) -> Result<(), ()> {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,12 @@ use topola::{
|
||||||
stepper::{Abort, Step},
|
stepper::{Abort, Step},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::interaction::{
|
||||||
|
InteractionContext, InteractionError, InteractionStatus, InteractionStepper,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct ActivityContext<'a> {
|
pub struct ActivityContext<'a> {
|
||||||
|
pub interaction: InteractionContext,
|
||||||
pub invoker: &'a mut Invoker<SpecctraMesadata>,
|
pub invoker: &'a mut Invoker<SpecctraMesadata>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,6 +30,15 @@ pub enum ActivityStatus {
|
||||||
Finished(String),
|
Finished(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<InteractionStatus> for ActivityStatus {
|
||||||
|
fn from(status: InteractionStatus) -> Self {
|
||||||
|
match status {
|
||||||
|
InteractionStatus::Running => ActivityStatus::Running,
|
||||||
|
InteractionStatus::Finished(msg) => ActivityStatus::Finished(msg),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<InvokerStatus> for ActivityStatus {
|
impl From<InvokerStatus> for ActivityStatus {
|
||||||
fn from(status: InvokerStatus) -> Self {
|
fn from(status: InvokerStatus) -> Self {
|
||||||
match status {
|
match status {
|
||||||
|
|
@ -46,18 +60,23 @@ impl TryInto<()> for ActivityStatus {
|
||||||
|
|
||||||
#[derive(Error, Debug, Clone)]
|
#[derive(Error, Debug, Clone)]
|
||||||
pub enum ActivityError {
|
pub enum ActivityError {
|
||||||
|
#[error(transparent)]
|
||||||
|
Interaction(#[from] InteractionError),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Invoker(#[from] InvokerError),
|
Invoker(#[from] InvokerError),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ActivityStepper {
|
pub enum ActivityStepper {
|
||||||
// There will be another variant for interactive activities here soon. (TODO)
|
Interaction(InteractionStepper),
|
||||||
Execution(ExecutionStepper),
|
Execution(ExecutionStepper),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Step<ActivityContext<'_>, ActivityStatus, ActivityError, ()> for ActivityStepper {
|
impl Step<ActivityContext<'_>, ActivityStatus, ActivityError, ()> for ActivityStepper {
|
||||||
fn step(&mut self, context: &mut ActivityContext) -> Result<ActivityStatus, ActivityError> {
|
fn step(&mut self, context: &mut ActivityContext) -> Result<ActivityStatus, ActivityError> {
|
||||||
match self {
|
match self {
|
||||||
|
ActivityStepper::Interaction(interaction) => {
|
||||||
|
Ok(interaction.step(&mut context.interaction)?.into())
|
||||||
|
}
|
||||||
ActivityStepper::Execution(execution) => Ok(execution.step(context.invoker)?.into()),
|
ActivityStepper::Execution(execution) => Ok(execution.step(context.invoker)?.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -66,6 +85,9 @@ impl Step<ActivityContext<'_>, ActivityStatus, ActivityError, ()> for ActivitySt
|
||||||
impl Abort<ActivityContext<'_>> for ActivityStepper {
|
impl Abort<ActivityContext<'_>> for ActivityStepper {
|
||||||
fn abort(&mut self, context: &mut ActivityContext) {
|
fn abort(&mut self, context: &mut ActivityContext) {
|
||||||
match self {
|
match self {
|
||||||
|
ActivityStepper::Interaction(interaction) => {
|
||||||
|
Ok(interaction.abort(&mut context.interaction))
|
||||||
|
}
|
||||||
ActivityStepper::Execution(execution) => execution.finish(context.invoker), // TODO.
|
ActivityStepper::Execution(execution) => execution.finish(context.invoker), // TODO.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -75,6 +97,7 @@ impl GetMaybeNavmesh for ActivityStepper {
|
||||||
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
||||||
fn maybe_navmesh(&self) -> Option<&Navmesh> {
|
fn maybe_navmesh(&self) -> Option<&Navmesh> {
|
||||||
match self {
|
match self {
|
||||||
|
ActivityStepper::Interaction(interaction) => interaction.maybe_navmesh(),
|
||||||
ActivityStepper::Execution(execution) => execution.maybe_navmesh(),
|
ActivityStepper::Execution(execution) => execution.maybe_navmesh(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -84,6 +107,7 @@ impl GetMaybeTrace for ActivityStepper {
|
||||||
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
||||||
fn maybe_trace(&self) -> Option<&TraceStepper> {
|
fn maybe_trace(&self) -> Option<&TraceStepper> {
|
||||||
match self {
|
match self {
|
||||||
|
ActivityStepper::Interaction(interaction) => interaction.maybe_trace(),
|
||||||
ActivityStepper::Execution(execution) => execution.maybe_trace(),
|
ActivityStepper::Execution(execution) => execution.maybe_trace(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -93,6 +117,7 @@ impl GetGhosts for ActivityStepper {
|
||||||
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
||||||
fn ghosts(&self) -> &[PrimitiveShape] {
|
fn ghosts(&self) -> &[PrimitiveShape] {
|
||||||
match self {
|
match self {
|
||||||
|
ActivityStepper::Interaction(interaction) => interaction.ghosts(),
|
||||||
ActivityStepper::Execution(execution) => execution.ghosts(),
|
ActivityStepper::Execution(execution) => execution.ghosts(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -102,6 +127,7 @@ impl GetObstacles for ActivityStepper {
|
||||||
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
/// Implemented manually instead of with `enum_dispatch` because it doesn't work across crates.
|
||||||
fn obstacles(&self) -> &[PrimitiveIndex] {
|
fn obstacles(&self) -> &[PrimitiveIndex] {
|
||||||
match self {
|
match self {
|
||||||
|
ActivityStepper::Interaction(interaction) => interaction.obstacles(),
|
||||||
ActivityStepper::Execution(execution) => execution.obstacles(),
|
ActivityStepper::Execution(execution) => execution.obstacles(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ use crate::{
|
||||||
activity::{ActivityContext, ActivityStatus, ActivityStepperWithStatus},
|
activity::{ActivityContext, ActivityStatus, ActivityStepperWithStatus},
|
||||||
config::Config,
|
config::Config,
|
||||||
error_dialog::ErrorDialog,
|
error_dialog::ErrorDialog,
|
||||||
|
interaction::InteractionContext,
|
||||||
layers::Layers,
|
layers::Layers,
|
||||||
menu_bar::MenuBar,
|
menu_bar::MenuBar,
|
||||||
overlay::Overlay,
|
overlay::Overlay,
|
||||||
|
|
@ -170,7 +171,10 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref mut activity) = self.maybe_activity {
|
if let Some(ref mut activity) = self.maybe_activity {
|
||||||
return match activity.step(&mut ActivityContext { invoker }) {
|
return match activity.step(&mut ActivityContext {
|
||||||
|
interaction: InteractionContext {},
|
||||||
|
invoker,
|
||||||
|
}) {
|
||||||
Ok(ActivityStatus::Running) => true,
|
Ok(ActivityStatus::Running) => true,
|
||||||
Ok(ActivityStatus::Finished(..)) => false,
|
Ok(ActivityStatus::Finished(..)) => false,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
use thiserror::Error;
|
||||||
|
use topola::{
|
||||||
|
autorouter::invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles},
|
||||||
|
drawing::graph::PrimitiveIndex,
|
||||||
|
geometry::primitive::PrimitiveShape,
|
||||||
|
router::{navmesh::Navmesh, trace::TraceStepper},
|
||||||
|
stepper::{Abort, Step},
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::activity::ActivityStepperWithStatus;
|
||||||
|
|
||||||
|
pub struct InteractionContext {
|
||||||
|
// Empty for now.
|
||||||
|
// For example, this will contain mouse pointer position.
|
||||||
|
// (we will need an additional struct to hold a reference to a `Board<...>`)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum InteractionStatus {
|
||||||
|
Running,
|
||||||
|
Finished(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryInto<()> for InteractionStatus {
|
||||||
|
type Error = ();
|
||||||
|
fn try_into(self) -> Result<(), ()> {
|
||||||
|
match self {
|
||||||
|
InteractionStatus::Running => Err(()),
|
||||||
|
InteractionStatus::Finished(..) => Ok(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Error, Debug, Clone)]
|
||||||
|
pub enum InteractionError {
|
||||||
|
#[error("nothing to interact with")]
|
||||||
|
NothingToInteract,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum InteractionStepper {
|
||||||
|
// No interactions yet. This is only an empty skeleton for now.
|
||||||
|
// Examples of interactions:
|
||||||
|
// - interactively routing a track
|
||||||
|
// - interactively moving a footprint.
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Step<InteractionContext, InteractionStatus, InteractionError, ()> for InteractionStepper {
|
||||||
|
fn step(
|
||||||
|
&mut self,
|
||||||
|
invoker: &mut InteractionContext,
|
||||||
|
) -> Result<InteractionStatus, InteractionError> {
|
||||||
|
Ok(InteractionStatus::Finished(String::from("")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Abort<InteractionContext> for InteractionStepper {
|
||||||
|
fn abort(&mut self, context: &mut InteractionContext) {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetMaybeNavmesh for InteractionStepper {
|
||||||
|
fn maybe_navmesh(&self) -> Option<&Navmesh> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetMaybeTrace for InteractionStepper {
|
||||||
|
fn maybe_trace(&self) -> Option<&TraceStepper> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetGhosts for InteractionStepper {
|
||||||
|
fn ghosts(&self) -> &[PrimitiveShape] {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GetObstacles for InteractionStepper {
|
||||||
|
fn obstacles(&self) -> &[PrimitiveIndex] {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ mod activity;
|
||||||
mod app;
|
mod app;
|
||||||
mod config;
|
mod config;
|
||||||
mod error_dialog;
|
mod error_dialog;
|
||||||
|
mod interaction;
|
||||||
mod layers;
|
mod layers;
|
||||||
mod menu_bar;
|
mod menu_bar;
|
||||||
mod overlay;
|
mod overlay;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ use crate::{
|
||||||
action::{Action, Switch, Trigger},
|
action::{Action, Switch, Trigger},
|
||||||
activity::{ActivityContext, ActivityStatus, ActivityStepperWithStatus},
|
activity::{ActivityContext, ActivityStatus, ActivityStepperWithStatus},
|
||||||
app::{execute, handle_file},
|
app::{execute, handle_file},
|
||||||
|
interaction::InteractionContext,
|
||||||
overlay::Overlay,
|
overlay::Overlay,
|
||||||
translator::Translator,
|
translator::Translator,
|
||||||
viewport::Viewport,
|
viewport::Viewport,
|
||||||
|
|
@ -331,7 +332,10 @@ impl MenuBar {
|
||||||
} else if abort.consume_key_triggered(ctx, ui) {
|
} else if abort.consume_key_triggered(ctx, ui) {
|
||||||
if let Some(activity) = maybe_activity {
|
if let Some(activity) = maybe_activity {
|
||||||
if let Some(invoker) = arc_mutex_maybe_invoker.lock().unwrap().as_mut() {
|
if let Some(invoker) = arc_mutex_maybe_invoker.lock().unwrap().as_mut() {
|
||||||
activity.abort(&mut ActivityContext { invoker });
|
activity.abort(&mut ActivityContext {
|
||||||
|
interaction: InteractionContext {},
|
||||||
|
invoker,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if remove_bands.consume_key_triggered(ctx, ui) {
|
} else if remove_bands.consume_key_triggered(ctx, ui) {
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,3 @@ pub trait AccessMesadata: AccessRules {
|
||||||
/// Retrieves the index of a net by its name.
|
/// Retrieves the index of a net by its name.
|
||||||
fn netname_net(&self, netname: &str) -> Option<usize>;
|
fn netname_net(&self, netname: &str) -> Option<usize>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue