mirror of https://codeberg.org/topola/topola.git
egui: add structure Workspace for two-phase workflow
This commit is contained in:
parent
f02b7be878
commit
69f2ce3c2e
|
|
@ -29,36 +29,24 @@ use crate::{
|
|||
status_bar::StatusBar,
|
||||
translator::Translator,
|
||||
viewport::Viewport,
|
||||
workspace::Workspace,
|
||||
};
|
||||
|
||||
pub struct App {
|
||||
config: Config,
|
||||
translator: Translator,
|
||||
|
||||
maybe_overlay: Option<Overlay>,
|
||||
|
||||
arc_mutex_maybe_invoker: Arc<Mutex<Option<Invoker<SpecctraMesadata>>>>,
|
||||
|
||||
maybe_activity: Option<ActivityStepperWithStatus>,
|
||||
|
||||
content_channel: (
|
||||
Sender<Result<SpecctraDesign, SpecctraLoadingError>>,
|
||||
Receiver<Result<SpecctraDesign, SpecctraLoadingError>>,
|
||||
),
|
||||
history_channel: (
|
||||
Sender<std::io::Result<Result<History, serde_json::Error>>>,
|
||||
Receiver<std::io::Result<Result<History, serde_json::Error>>>,
|
||||
),
|
||||
|
||||
viewport: Viewport,
|
||||
|
||||
menu_bar: MenuBar,
|
||||
status_bar: StatusBar,
|
||||
|
||||
error_dialog: ErrorDialog,
|
||||
|
||||
maybe_layers: Option<Layers>,
|
||||
maybe_design: Option<SpecctraDesign>,
|
||||
maybe_workspace: Option<Workspace>,
|
||||
|
||||
update_counter: f32,
|
||||
}
|
||||
|
|
@ -68,17 +56,12 @@ impl Default for App {
|
|||
Self {
|
||||
config: Config::default(),
|
||||
translator: Translator::new(langid!("en-US")),
|
||||
maybe_overlay: None,
|
||||
arc_mutex_maybe_invoker: Arc::new(Mutex::new(None)),
|
||||
maybe_activity: None,
|
||||
content_channel: channel(),
|
||||
history_channel: channel(),
|
||||
viewport: Viewport::new(),
|
||||
menu_bar: MenuBar::new(),
|
||||
status_bar: StatusBar::new(),
|
||||
error_dialog: ErrorDialog::new(),
|
||||
maybe_layers: None,
|
||||
maybe_design: None,
|
||||
maybe_workspace: None,
|
||||
update_counter: 0.0,
|
||||
}
|
||||
}
|
||||
|
|
@ -113,8 +96,11 @@ impl App {
|
|||
fn update_state(&mut self) -> bool {
|
||||
if let Ok(data) = self.content_channel.1.try_recv() {
|
||||
match data {
|
||||
Ok(design) => match self.load_specctra_dsn(design) {
|
||||
Ok(()) => {}
|
||||
Ok(design) => match Workspace::new(design, &self.translator) {
|
||||
Ok(ws) => {
|
||||
self.maybe_workspace = Some(ws);
|
||||
self.viewport.scheduled_zoom_to_fit = true;
|
||||
}
|
||||
Err(err) => {
|
||||
self.error_dialog
|
||||
.push_error("tr-module-specctra-dsn-file-loader", err);
|
||||
|
|
@ -144,76 +130,11 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(invoker) = self.arc_mutex_maybe_invoker.lock().unwrap().as_mut() {
|
||||
if let Ok(data) = self.history_channel.1.try_recv() {
|
||||
let tr = &self.translator;
|
||||
match data {
|
||||
Ok(Ok(data)) => {
|
||||
invoker.replay(data);
|
||||
if let Some(workspace) = &mut self.maybe_workspace {
|
||||
return workspace.update_state(&self.translator, &mut self.error_dialog);
|
||||
}
|
||||
Ok(Err(err)) => {
|
||||
self.error_dialog.push_error(
|
||||
"tr-module-history-file-loader",
|
||||
format!(
|
||||
"{}; {}",
|
||||
tr.text("tr-error-failed-to-parse-as-history-json"),
|
||||
err
|
||||
),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
self.error_dialog.push_error(
|
||||
"tr-module-history-file-loader",
|
||||
format!("{}; {}", tr.text("tr-error-unable-to-read-file"), err),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref mut activity) = self.maybe_activity {
|
||||
return match activity.step(&mut ActivityContext {
|
||||
interaction: InteractionContext {},
|
||||
invoker,
|
||||
}) {
|
||||
Ok(ActivityStatus::Running) => true,
|
||||
Ok(ActivityStatus::Finished(..)) => false,
|
||||
Err(err) => {
|
||||
self.error_dialog
|
||||
.push_error("tr-module-invoker", format!("{}", err));
|
||||
false
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn load_specctra_dsn(&mut self, design: SpecctraDesign) -> Result<(), String> {
|
||||
let tr = &self.translator;
|
||||
let board = design.make_board();
|
||||
let overlay = Overlay::new(&board).map_err(|err| {
|
||||
format!(
|
||||
"{}; {}",
|
||||
tr.text("tr-error-unable-to-initialize-overlay"),
|
||||
err
|
||||
)
|
||||
})?;
|
||||
let layers = Layers::new(&board);
|
||||
let autorouter = Autorouter::new(board).map_err(|err| {
|
||||
format!(
|
||||
"{}; {}",
|
||||
tr.text("tr-error-unable-to-initialize-autorouter"),
|
||||
err
|
||||
)
|
||||
})?;
|
||||
self.maybe_overlay = Some(overlay);
|
||||
self.maybe_layers = Some(layers);
|
||||
self.maybe_design = Some(design);
|
||||
self.arc_mutex_maybe_invoker = Arc::new(Mutex::new(Some(Invoker::new(autorouter))));
|
||||
self.viewport.scheduled_zoom_to_fit = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for App {
|
||||
|
|
@ -228,37 +149,32 @@ impl eframe::App for App {
|
|||
ctx,
|
||||
&self.translator,
|
||||
self.content_channel.0.clone(),
|
||||
self.history_channel.0.clone(),
|
||||
self.arc_mutex_maybe_invoker.clone(),
|
||||
&mut self.maybe_activity,
|
||||
&mut self.viewport,
|
||||
&mut self.maybe_overlay,
|
||||
&self.maybe_design,
|
||||
self.maybe_workspace.as_mut(),
|
||||
);
|
||||
|
||||
self.advance_state_by_dt(ctx.input(|i| i.stable_dt));
|
||||
|
||||
self.status_bar
|
||||
.update(ctx, &self.translator, &self.viewport, &self.maybe_activity);
|
||||
self.status_bar.update(
|
||||
ctx,
|
||||
&self.translator,
|
||||
&self.viewport,
|
||||
self.maybe_workspace
|
||||
.as_ref()
|
||||
.and_then(|w| w.maybe_activity.as_ref()),
|
||||
);
|
||||
|
||||
if self.menu_bar.show_layer_manager {
|
||||
if let Some(ref mut layers) = self.maybe_layers {
|
||||
if let Some(invoker) = self.arc_mutex_maybe_invoker.lock().unwrap().as_ref() {
|
||||
layers.update(ctx, invoker.autorouter().board());
|
||||
}
|
||||
if let Some(workspace) = &mut self.maybe_workspace {
|
||||
workspace.update_layers(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
self.error_dialog.update(ctx, &self.translator);
|
||||
|
||||
let _viewport_rect = self.viewport.update(
|
||||
ctx,
|
||||
&self.menu_bar,
|
||||
&mut self.arc_mutex_maybe_invoker.lock().unwrap(),
|
||||
&mut self.maybe_activity,
|
||||
&mut self.maybe_overlay,
|
||||
&self.maybe_layers,
|
||||
);
|
||||
let _viewport_rect =
|
||||
self.viewport
|
||||
.update(ctx, &self.menu_bar, self.maybe_workspace.as_mut());
|
||||
|
||||
if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ mod painter;
|
|||
mod status_bar;
|
||||
mod translator;
|
||||
mod viewport;
|
||||
mod workspace;
|
||||
|
||||
use app::App;
|
||||
use sys_locale::get_locale;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ use crate::{
|
|||
overlay::Overlay,
|
||||
translator::Translator,
|
||||
viewport::Viewport,
|
||||
workspace::Workspace,
|
||||
};
|
||||
|
||||
pub struct MenuBar {
|
||||
|
|
@ -64,12 +65,8 @@ impl MenuBar {
|
|||
ctx: &egui::Context,
|
||||
tr: &Translator,
|
||||
content_sender: Sender<Result<SpecctraDesign, SpecctraLoadingError>>,
|
||||
history_sender: Sender<std::io::Result<Result<History, serde_json::Error>>>,
|
||||
arc_mutex_maybe_invoker: Arc<Mutex<Option<Invoker<SpecctraMesadata>>>>,
|
||||
maybe_activity: &mut Option<ActivityStepperWithStatus>,
|
||||
viewport: &mut Viewport,
|
||||
maybe_overlay: &mut Option<Overlay>,
|
||||
maybe_design: &Option<SpecctraDesign>,
|
||||
maybe_workspace: Option<&mut Workspace>,
|
||||
) -> Result<(), InvokerError> {
|
||||
let mut open_design = Trigger::new(Action::new(
|
||||
tr.text("tr-menu-file-open"),
|
||||
|
|
@ -258,22 +255,23 @@ impl MenuBar {
|
|||
}
|
||||
});
|
||||
} else if export_session.consume_key_triggered(ctx, ui) {
|
||||
if let Some(design) = maybe_design {
|
||||
if let Some(invoker) = arc_mutex_maybe_invoker.lock().unwrap().as_ref() {
|
||||
if let Some(workspace) = maybe_workspace {
|
||||
let invoker = workspace.invoker.lock().unwrap();
|
||||
let ctx = ui.ctx().clone();
|
||||
let board = invoker.autorouter().board();
|
||||
|
||||
// FIXME: I don't know how to avoid buffering the entire exported file
|
||||
let mut writebuf = vec![];
|
||||
|
||||
design.write_ses(board, &mut writebuf);
|
||||
workspace.design.write_ses(board, &mut writebuf);
|
||||
|
||||
let mut dialog = rfd::AsyncFileDialog::new();
|
||||
if let Some(filename) = Path::new(design.get_name()).file_stem() {
|
||||
if let Some(filename) = Path::new(workspace.design.get_name()).file_stem() {
|
||||
if let Some(filename) = filename.to_str() {
|
||||
dialog = dialog.set_file_name(filename);
|
||||
}
|
||||
}
|
||||
|
||||
let task = dialog
|
||||
.add_filter(tr.text("tr-menu-open-specctra-session-file"), &["ses"])
|
||||
.save_file();
|
||||
|
|
@ -285,10 +283,11 @@ impl MenuBar {
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if import_history.consume_key_triggered(ctx, ui) {
|
||||
if let Some(workspace) = maybe_workspace {
|
||||
let ctx = ctx.clone();
|
||||
let task = rfd::AsyncFileDialog::new().pick_file();
|
||||
let history_sender = workspace.history_channel.0.clone();
|
||||
|
||||
execute(async move {
|
||||
if let Some(file_handle) = task.await {
|
||||
|
|
@ -303,8 +302,10 @@ impl MenuBar {
|
|||
ctx.request_repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if export_history.consume_key_triggered(ctx, ui) {
|
||||
if let Some(invoker) = arc_mutex_maybe_invoker.lock().unwrap().as_ref() {
|
||||
if let Some(workspace) = maybe_workspace {
|
||||
let invoker = workspace.invoker.lock().unwrap();
|
||||
let ctx = ctx.clone();
|
||||
let task = rfd::AsyncFileDialog::new().save_file();
|
||||
|
||||
|
|
@ -322,49 +323,46 @@ impl MenuBar {
|
|||
} else if quit.consume_key_triggered(ctx, ui) {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
} else if undo.consume_key_triggered(ctx, ui) {
|
||||
if let Some(invoker) = arc_mutex_maybe_invoker.lock().unwrap().as_mut() {
|
||||
invoker.undo();
|
||||
if let Some(workspace) = maybe_workspace {
|
||||
workspace.invoker.lock().unwrap().undo();
|
||||
}
|
||||
} else if redo.consume_key_triggered(ctx, ui) {
|
||||
if let Some(invoker) = arc_mutex_maybe_invoker.lock().unwrap().as_mut() {
|
||||
invoker.redo();
|
||||
if let Some(workspace) = maybe_workspace {
|
||||
workspace.invoker.lock().unwrap().redo();
|
||||
}
|
||||
} else if abort.consume_key_triggered(ctx, ui) {
|
||||
if let Some(activity) = maybe_activity {
|
||||
if let Some(invoker) = arc_mutex_maybe_invoker.lock().unwrap().as_mut() {
|
||||
if let Some(workspace) = maybe_workspace {
|
||||
if let Some(activity) = &mut workspace.maybe_activity {
|
||||
activity.abort(&mut ActivityContext {
|
||||
interaction: InteractionContext {},
|
||||
invoker,
|
||||
invoker: &mut *workspace.invoker.lock().unwrap(),
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if remove_bands.consume_key_triggered(ctx, ui) {
|
||||
if maybe_activity.as_mut().map_or(true, |activity| {
|
||||
if let Some(workspace) = maybe_workspace {
|
||||
if workspace.maybe_activity.as_mut().map_or(true, |activity| {
|
||||
matches!(activity.maybe_status(), Some(ActivityStatus::Finished(..)))
|
||||
}) {
|
||||
if let (Some(invoker), Some(ref mut overlay)) = (
|
||||
arc_mutex_maybe_invoker.lock().unwrap().as_mut(),
|
||||
maybe_overlay,
|
||||
) {
|
||||
let selection = overlay.take_selection();
|
||||
*maybe_activity = Some(ActivityStepperWithStatus::new_execution(
|
||||
invoker.execute_stepper(Command::RemoveBands(
|
||||
selection.band_selection,
|
||||
))?,
|
||||
));
|
||||
let mut invoker = workspace.invoker.lock().unwrap();
|
||||
let selection = workspace.overlay.take_selection();
|
||||
workspace.maybe_activity = Some(
|
||||
ActivityStepperWithStatus::new_execution(invoker.execute_stepper(
|
||||
Command::RemoveBands(selection.band_selection),
|
||||
)?),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if place_via.consume_key_enabled(ctx, ui, &mut self.is_placing_via) {
|
||||
} else if autoroute.consume_key_triggered(ctx, ui) {
|
||||
if maybe_activity.as_mut().map_or(true, |activity| {
|
||||
if let Some(workspace) = maybe_workspace {
|
||||
if workspace.maybe_activity.as_mut().map_or(true, |activity| {
|
||||
matches!(activity.maybe_status(), Some(ActivityStatus::Finished(..)))
|
||||
}) {
|
||||
if let (Some(invoker), Some(ref mut overlay)) = (
|
||||
arc_mutex_maybe_invoker.lock().unwrap().as_mut(),
|
||||
maybe_overlay,
|
||||
) {
|
||||
let selection = overlay.take_selection();
|
||||
*maybe_activity = Some(ActivityStepperWithStatus::new_execution(
|
||||
let mut invoker = workspace.invoker.lock().unwrap();
|
||||
let selection = workspace.overlay.take_selection();
|
||||
workspace.maybe_activity =
|
||||
Some(ActivityStepperWithStatus::new_execution(
|
||||
invoker.execute_stepper(Command::Autoroute(
|
||||
selection.pin_selection,
|
||||
self.autorouter_options,
|
||||
|
|
@ -373,15 +371,14 @@ impl MenuBar {
|
|||
}
|
||||
}
|
||||
} else if compare_detours.consume_key_triggered(ctx, ui) {
|
||||
if maybe_activity.as_mut().map_or(true, |activity| {
|
||||
if let Some(workspace) = maybe_workspace {
|
||||
if workspace.maybe_activity.as_mut().map_or(true, |activity| {
|
||||
matches!(activity.maybe_status(), Some(ActivityStatus::Finished(..)))
|
||||
}) {
|
||||
if let (Some(invoker), Some(ref mut overlay)) = (
|
||||
arc_mutex_maybe_invoker.lock().unwrap().as_mut(),
|
||||
maybe_overlay,
|
||||
) {
|
||||
let selection = overlay.take_selection();
|
||||
*maybe_activity = Some(ActivityStepperWithStatus::new_execution(
|
||||
let mut invoker = workspace.invoker.lock().unwrap();
|
||||
let selection = workspace.overlay.take_selection();
|
||||
workspace.maybe_activity =
|
||||
Some(ActivityStepperWithStatus::new_execution(
|
||||
invoker.execute_stepper(Command::CompareDetours(
|
||||
selection.pin_selection,
|
||||
self.autorouter_options,
|
||||
|
|
@ -390,19 +387,17 @@ impl MenuBar {
|
|||
}
|
||||
}
|
||||
} else if measure_length.consume_key_triggered(ctx, ui) {
|
||||
if maybe_activity.as_mut().map_or(true, |activity| {
|
||||
if let Some(workspace) = maybe_workspace {
|
||||
if workspace.maybe_activity.as_mut().map_or(true, |activity| {
|
||||
matches!(activity.maybe_status(), Some(ActivityStatus::Finished(..)))
|
||||
}) {
|
||||
if let (Some(invoker), Some(ref mut overlay)) = (
|
||||
arc_mutex_maybe_invoker.lock().unwrap().as_mut(),
|
||||
maybe_overlay,
|
||||
) {
|
||||
let selection = overlay.take_selection();
|
||||
*maybe_activity = Some(ActivityStepperWithStatus::new_execution(
|
||||
invoker.execute_stepper(Command::MeasureLength(
|
||||
selection.band_selection,
|
||||
))?,
|
||||
));
|
||||
let mut invoker = workspace.invoker.lock().unwrap();
|
||||
let selection = workspace.overlay.take_selection();
|
||||
workspace.maybe_activity = Some(
|
||||
ActivityStepperWithStatus::new_execution(invoker.execute_stepper(
|
||||
Command::MeasureLength(selection.band_selection),
|
||||
)?),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ impl StatusBar {
|
|||
ctx: &egui::Context,
|
||||
tr: &Translator,
|
||||
viewport: &Viewport,
|
||||
maybe_activity: &Option<ActivityStepperWithStatus>,
|
||||
maybe_activity: Option<&ActivityStepperWithStatus>,
|
||||
) {
|
||||
egui::TopBottomPanel::bottom("status_bar").show(ctx, |ui| {
|
||||
let latest_pos = viewport.transform.inverse()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use topola::{
|
|||
|
||||
use crate::{
|
||||
activity::ActivityStepperWithStatus, layers::Layers, menu_bar::MenuBar, overlay::Overlay,
|
||||
painter::Painter,
|
||||
painter::Painter, workspace::Workspace,
|
||||
};
|
||||
|
||||
pub struct Viewport {
|
||||
|
|
@ -41,22 +41,13 @@ impl Viewport {
|
|||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
top: &MenuBar,
|
||||
maybe_invoker: &mut Option<Invoker<SpecctraMesadata>>,
|
||||
maybe_activity: &mut Option<ActivityStepperWithStatus>,
|
||||
maybe_overlay: &mut Option<Overlay>,
|
||||
maybe_layers: &Option<Layers>,
|
||||
mut maybe_workspace: Option<&mut Workspace>,
|
||||
) -> egui::Rect {
|
||||
let viewport_rect = self.paint(
|
||||
ctx,
|
||||
top,
|
||||
maybe_invoker,
|
||||
maybe_activity,
|
||||
maybe_overlay,
|
||||
maybe_layers,
|
||||
);
|
||||
let viewport_rect = self.paint(ctx, top, maybe_workspace.as_deref_mut());
|
||||
|
||||
if self.scheduled_zoom_to_fit {
|
||||
self.zoom_to_fit(maybe_invoker, &viewport_rect);
|
||||
let mut maybe_invoker = maybe_workspace.as_ref().map(|w| w.invoker.lock().unwrap());
|
||||
self.zoom_to_fit(maybe_invoker.as_deref_mut(), &viewport_rect);
|
||||
}
|
||||
|
||||
viewport_rect
|
||||
|
|
@ -66,10 +57,7 @@ impl Viewport {
|
|||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
top: &MenuBar,
|
||||
maybe_invoker: &mut Option<Invoker<SpecctraMesadata>>,
|
||||
maybe_activity: &mut Option<ActivityStepperWithStatus>,
|
||||
maybe_overlay: &mut Option<Overlay>,
|
||||
maybe_layers: &Option<Layers>,
|
||||
maybe_workspace: Option<&mut Workspace>,
|
||||
) -> egui::Rect {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
egui::Frame::canvas(ui.style()).show(ui, |ui| {
|
||||
|
|
@ -86,7 +74,11 @@ impl Viewport {
|
|||
|
||||
let mut painter = Painter::new(ui, self.transform, top.show_bboxes);
|
||||
|
||||
if let Some(ref mut invoker) = maybe_invoker {
|
||||
if let Some(workspace) = maybe_workspace {
|
||||
let mut invoker = workspace.invoker.lock().unwrap();
|
||||
let layers = &mut workspace.layers;
|
||||
let overlay = &mut workspace.overlay;
|
||||
|
||||
if ctx.input(|i| i.pointer.any_click()) {
|
||||
if top.is_placing_via {
|
||||
invoker.execute(
|
||||
|
|
@ -100,7 +92,7 @@ impl Viewport {
|
|||
maybe_net: Some(1234),
|
||||
}),
|
||||
);
|
||||
} else if let Some(overlay) = maybe_overlay {
|
||||
} else {
|
||||
overlay.click(
|
||||
invoker.autorouter().board(),
|
||||
point! {x: latest_pos.x as f64, y: -latest_pos.y as f64},
|
||||
|
|
@ -108,13 +100,7 @@ impl Viewport {
|
|||
}
|
||||
}
|
||||
|
||||
if let (Some(invoker), Some(overlay)) = (
|
||||
maybe_invoker,
|
||||
maybe_overlay,
|
||||
) {
|
||||
let board = invoker.autorouter().board();
|
||||
|
||||
if let Some(layers) = maybe_layers {
|
||||
for i in (0..layers.visible.len()).rev() {
|
||||
if layers.visible[i] {
|
||||
for primitive in board.layout().drawing().layer_primitive_nodes(i) {
|
||||
|
|
@ -125,8 +111,7 @@ impl Viewport {
|
|||
.contains_node(board, GenericNode::Primitive(primitive))
|
||||
{
|
||||
layers.highlight_colors[i]
|
||||
} else {
|
||||
if let Some(activity) = maybe_activity {
|
||||
} else if let Some(activity) = &mut workspace.maybe_activity {
|
||||
if activity.obstacles().contains(&primitive) {
|
||||
layers.highlight_colors[i]
|
||||
} else {
|
||||
|
|
@ -134,7 +119,6 @@ impl Viewport {
|
|||
}
|
||||
} else {
|
||||
layers.colors[i]
|
||||
}
|
||||
};
|
||||
|
||||
painter.paint_primitive(&shape, color);
|
||||
|
|
@ -154,19 +138,15 @@ impl Viewport {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if top.show_ratsnest {
|
||||
for edge in overlay.ratsnest().graph().edge_references() {
|
||||
let from = overlay
|
||||
.ratsnest()
|
||||
.graph()
|
||||
let graph = overlay.ratsnest().graph();
|
||||
for edge in graph.edge_references() {
|
||||
let from = graph
|
||||
.node_weight(edge.source())
|
||||
.unwrap()
|
||||
.pos;
|
||||
let to = overlay
|
||||
.ratsnest()
|
||||
.graph()
|
||||
let to = graph
|
||||
.node_weight(edge.target())
|
||||
.unwrap()
|
||||
.pos;
|
||||
|
|
@ -180,7 +160,7 @@ impl Viewport {
|
|||
}
|
||||
|
||||
if top.show_navmesh {
|
||||
if let Some(activity) = maybe_activity {
|
||||
if let Some(activity) = &mut workspace.maybe_activity {
|
||||
if let Some(navmesh) = activity.maybe_navmesh() {
|
||||
for edge in navmesh.edge_references() {
|
||||
let mut from = PrimitiveIndex::from(navmesh.node_weight(edge.source()).unwrap().node)
|
||||
|
|
@ -245,7 +225,7 @@ impl Viewport {
|
|||
painter.paint_bbox(root_bbox);
|
||||
}
|
||||
|
||||
if let Some(activity) = maybe_activity {
|
||||
if let Some(activity) = &mut workspace.maybe_activity {
|
||||
for ghost in activity.ghosts().iter() {
|
||||
painter.paint_primitive(&ghost, egui::Color32::from_rgb(75, 75, 150));
|
||||
}
|
||||
|
|
@ -271,7 +251,6 @@ impl Viewport {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewport_rect
|
||||
})
|
||||
|
|
@ -280,7 +259,7 @@ impl Viewport {
|
|||
|
||||
fn zoom_to_fit(
|
||||
&mut self,
|
||||
maybe_invoker: &mut Option<Invoker<SpecctraMesadata>>,
|
||||
maybe_invoker: Option<&mut Invoker<SpecctraMesadata>>,
|
||||
viewport_rect: &egui::Rect,
|
||||
) {
|
||||
if self.scheduled_zoom_to_fit {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,121 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
future::Future,
|
||||
io,
|
||||
sync::{
|
||||
mpsc::{channel, Receiver, Sender},
|
||||
Arc, Mutex,
|
||||
},
|
||||
};
|
||||
use unic_langid::{langid, LanguageIdentifier};
|
||||
|
||||
use topola::{
|
||||
autorouter::{history::History, invoker::Invoker, Autorouter},
|
||||
specctra::{
|
||||
design::{LoadingError as SpecctraLoadingError, SpecctraDesign},
|
||||
mesadata::SpecctraMesadata,
|
||||
},
|
||||
stepper::Step,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
activity::{ActivityContext, ActivityStatus, ActivityStepperWithStatus},
|
||||
error_dialog::ErrorDialog,
|
||||
interaction::InteractionContext,
|
||||
layers::Layers,
|
||||
menu_bar::MenuBar,
|
||||
overlay::Overlay,
|
||||
status_bar::StatusBar,
|
||||
translator::Translator,
|
||||
viewport::Viewport,
|
||||
};
|
||||
|
||||
/// A loaded design and associated structures
|
||||
pub struct Workspace {
|
||||
pub design: SpecctraDesign,
|
||||
pub layers: Layers,
|
||||
pub overlay: Overlay,
|
||||
pub invoker: Arc<Mutex<Invoker<SpecctraMesadata>>>,
|
||||
|
||||
pub maybe_activity: Option<ActivityStepperWithStatus>,
|
||||
|
||||
pub history_channel: (
|
||||
Sender<std::io::Result<Result<History, serde_json::Error>>>,
|
||||
Receiver<std::io::Result<Result<History, serde_json::Error>>>,
|
||||
),
|
||||
}
|
||||
|
||||
impl Workspace {
|
||||
pub fn new(design: SpecctraDesign, tr: &Translator) -> Result<Self, String> {
|
||||
let board = design.make_board();
|
||||
let overlay = Overlay::new(&board).map_err(|err| {
|
||||
format!(
|
||||
"{}; {}",
|
||||
tr.text("tr-error_unable-to-initialize-overlay"),
|
||||
err
|
||||
)
|
||||
})?;
|
||||
let layers = Layers::new(&board);
|
||||
let autorouter = Autorouter::new(board).map_err(|err| {
|
||||
format!(
|
||||
"{}; {}",
|
||||
tr.text("tr-error_unable-to-initialize-autorouter"),
|
||||
err
|
||||
)
|
||||
})?;
|
||||
Ok(Self {
|
||||
design,
|
||||
layers,
|
||||
overlay,
|
||||
invoker: Arc::new(Mutex::new(Invoker::new(autorouter))),
|
||||
maybe_activity: None,
|
||||
history_channel: channel(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update_state(&mut self, tr: &Translator, error_dialog: &mut ErrorDialog) -> bool {
|
||||
if let Ok(data) = self.history_channel.1.try_recv() {
|
||||
match data {
|
||||
Ok(Ok(data)) => {
|
||||
self.invoker.lock().unwrap().replay(data);
|
||||
}
|
||||
Ok(Err(err)) => {
|
||||
error_dialog.push_error(
|
||||
"tr-module-history-file-loader",
|
||||
format!(
|
||||
"{}; {}",
|
||||
tr.text("tr-error_failed-to-parse-as-history-json"),
|
||||
err
|
||||
),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
error_dialog.push_error(
|
||||
"tr-module-history-file-loader",
|
||||
format!("{}; {}", tr.text("tr-error_unable-to-read-file"), err),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(activity) = &mut self.maybe_activity {
|
||||
return match activity.step(&mut ActivityContext {
|
||||
interaction: InteractionContext {},
|
||||
invoker: &mut *self.invoker.lock().unwrap(),
|
||||
}) {
|
||||
Ok(ActivityStatus::Running) => true,
|
||||
Ok(ActivityStatus::Finished(..)) => false,
|
||||
Err(err) => {
|
||||
error_dialog.push_error("tr-module-invoker", format!("{}", err));
|
||||
false
|
||||
}
|
||||
};
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub fn update_layers(&mut self, ctx: &egui::Context) {
|
||||
let invoker = self.invoker.lock().unwrap();
|
||||
self.layers.update(ctx, invoker.autorouter().board());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue