mirror of https://codeberg.org/topola/topola.git
egui: draw routing start and stop
This commit is contained in:
parent
9ac4c780b5
commit
a5dcacdd69
|
|
@ -115,14 +115,6 @@ impl Autoroute {
|
||||||
(from_dot, to_dot)
|
(from_dot, to_dot)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_navmesh(
|
|
||||||
layout: &Layout<impl RulesTrait>,
|
|
||||||
from: FixedDotIndex,
|
|
||||||
to: FixedDotIndex,
|
|
||||||
) -> Navmesh {
|
|
||||||
Navmesh::new(layout, from, to).unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn navmesh(&self) -> &Navmesh {
|
pub fn navmesh(&self) -> &Navmesh {
|
||||||
&self.navmesh
|
&self.navmesh
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ use std::{
|
||||||
use topola::{
|
use topola::{
|
||||||
autorouter::Autorouter,
|
autorouter::Autorouter,
|
||||||
drawing::{
|
drawing::{
|
||||||
|
dot::FixedDotIndex,
|
||||||
graph::{MakePrimitive, PrimitiveIndex},
|
graph::{MakePrimitive, PrimitiveIndex},
|
||||||
primitive::MakePrimitiveShape,
|
primitive::MakePrimitiveShape,
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
|
|
@ -38,6 +39,8 @@ use crate::{overlay::Overlay, painter::Painter};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct SharedData {
|
struct SharedData {
|
||||||
|
pub from: Option<FixedDotIndex>,
|
||||||
|
pub to: Option<FixedDotIndex>,
|
||||||
pub navmesh: Option<Navmesh>,
|
pub navmesh: Option<Navmesh>,
|
||||||
pub path: Vec<VertexIndex>,
|
pub path: Vec<VertexIndex>,
|
||||||
pub ghosts: Vec<PrimitiveShape>,
|
pub ghosts: Vec<PrimitiveShape>,
|
||||||
|
|
@ -195,21 +198,28 @@ impl eframe::App for App {
|
||||||
if ui.button("Autoroute").clicked() {
|
if ui.button("Autoroute").clicked() {
|
||||||
if let Some(layout_arc_mutex) = &self.layout {
|
if let Some(layout_arc_mutex) = &self.layout {
|
||||||
let layout = layout_arc_mutex.clone();
|
let layout = layout_arc_mutex.clone();
|
||||||
let shared_data = self.shared_data.clone();
|
let shared_data_arc_mutex = self.shared_data.clone();
|
||||||
|
|
||||||
execute(async move {
|
execute(async move {
|
||||||
let mut autorouter = Autorouter::new(layout).unwrap();
|
let mut autorouter = Autorouter::new(layout).unwrap();
|
||||||
if let Some(mut it) = autorouter.autoroute_iter() {
|
if let Some(mut autoroute) = autorouter.autoroute_iter() {
|
||||||
shared_data.lock().unwrap().navmesh = Some(it.navmesh().clone());
|
let from_to = autoroute.from_to(&autorouter);
|
||||||
|
|
||||||
while let Some(()) = it.next(
|
{
|
||||||
|
let mut shared_data = shared_data_arc_mutex.lock().unwrap();
|
||||||
|
shared_data.from = Some(from_to.0);
|
||||||
|
shared_data.to = Some(from_to.1);
|
||||||
|
shared_data.navmesh = Some(autoroute.navmesh().clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
while let Some(()) = autoroute.next(
|
||||||
&mut autorouter,
|
&mut autorouter,
|
||||||
&mut DebugRouterObserver {
|
&mut DebugRouterObserver {
|
||||||
shared_data: shared_data.clone(),
|
shared_data: shared_data_arc_mutex.clone(),
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
shared_data.lock().unwrap().navmesh =
|
shared_data_arc_mutex.lock().unwrap().navmesh =
|
||||||
Some(it.navmesh().clone());
|
Some(autoroute.navmesh().clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -374,6 +384,24 @@ impl eframe::App for App {
|
||||||
for ghost in shared_data.ghosts.iter() {
|
for ghost in shared_data.ghosts.iter() {
|
||||||
painter.paint_primitive(&ghost, egui::Color32::from_rgb(75, 75, 150));
|
painter.paint_primitive(&ghost, egui::Color32::from_rgb(75, 75, 150));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let (Some(from), Some(to)) = (shared_data.from, shared_data.to) {
|
||||||
|
painter.paint_dot(
|
||||||
|
Circle {
|
||||||
|
pos: layout.drawing().primitive(from).shape().center(),
|
||||||
|
r: 20.0,
|
||||||
|
},
|
||||||
|
egui::Color32::from_rgb(255, 255, 100),
|
||||||
|
);
|
||||||
|
painter.paint_dot(
|
||||||
|
Circle {
|
||||||
|
pos: layout.drawing().primitive(to).shape().center(),
|
||||||
|
r: 20.0,
|
||||||
|
},
|
||||||
|
egui::Color32::from_rgb(255, 255, 100),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//unreachable!();
|
//unreachable!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
use geo::{CoordsIter, Point, Polygon};
|
use geo::{CoordsIter, Point, Polygon};
|
||||||
use topola::geometry::primitive::{PrimitiveShape, PrimitiveShapeTrait};
|
use topola::{
|
||||||
|
geometry::primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
||||||
|
math::Circle,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Painter<'a> {
|
pub struct Painter<'a> {
|
||||||
ui: &'a mut egui::Ui,
|
ui: &'a mut egui::Ui,
|
||||||
|
|
@ -13,12 +16,7 @@ impl<'a> Painter<'a> {
|
||||||
|
|
||||||
pub fn paint_primitive(&mut self, shape: &PrimitiveShape, color: egui::epaint::Color32) {
|
pub fn paint_primitive(&mut self, shape: &PrimitiveShape, color: egui::epaint::Color32) {
|
||||||
let epaint_shape = match shape {
|
let epaint_shape = match shape {
|
||||||
PrimitiveShape::Dot(dot) => egui::Shape::circle_filled(
|
PrimitiveShape::Dot(dot) => self.dot_shape(dot.c, color),
|
||||||
self.transform
|
|
||||||
.transform_pos([dot.c.pos.x() as f32, -dot.c.pos.y() as f32].into()),
|
|
||||||
dot.c.r as f32 * self.transform.scale().x,
|
|
||||||
color,
|
|
||||||
),
|
|
||||||
PrimitiveShape::Seg(seg) => egui::Shape::line_segment(
|
PrimitiveShape::Seg(seg) => egui::Shape::line_segment(
|
||||||
[
|
[
|
||||||
self.transform
|
self.transform
|
||||||
|
|
@ -65,6 +63,20 @@ impl<'a> Painter<'a> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn paint_dot(&mut self, circle: Circle, color: egui::epaint::Color32) {
|
||||||
|
let shape = self.dot_shape(circle, color);
|
||||||
|
self.ui.painter().add(shape);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dot_shape(&mut self, circle: Circle, color: egui::epaint::Color32) -> egui::Shape {
|
||||||
|
egui::Shape::circle_filled(
|
||||||
|
self.transform
|
||||||
|
.transform_pos([circle.pos.x() as f32, -circle.pos.y() as f32].into()),
|
||||||
|
circle.r as f32 * self.transform.scale().x,
|
||||||
|
color,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn paint_polygon(&mut self, polygon: &Polygon, color: egui::epaint::Color32) {
|
pub fn paint_polygon(&mut self, polygon: &Polygon, color: egui::epaint::Color32) {
|
||||||
self.ui.painter().add(egui::Shape::convex_polygon(
|
self.ui.painter().add(egui::Shape::convex_polygon(
|
||||||
polygon
|
polygon
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue