mirror of https://codeberg.org/topola/topola.git
Display bboxes of primitives
This commit is contained in:
parent
7b5bffada8
commit
95694ac931
|
|
@ -5,9 +5,9 @@
|
||||||
use crate::{viewport::Viewport, workspace::Workspace};
|
use crate::{viewport::Viewport, workspace::Workspace};
|
||||||
use topola::{Joint, Polygon, Segment, SegmentId};
|
use topola::{Joint, Polygon, Segment, SegmentId};
|
||||||
|
|
||||||
pub struct Displayer {}
|
pub struct Display {}
|
||||||
|
|
||||||
impl Displayer {
|
impl Display {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {}
|
Self {}
|
||||||
}
|
}
|
||||||
|
|
@ -21,6 +21,7 @@ impl Displayer {
|
||||||
workspace: &Workspace,
|
workspace: &Workspace,
|
||||||
) {
|
) {
|
||||||
self.display_layout(ctx, ui, /*menu_bar,*/ viewport, workspace);
|
self.display_layout(ctx, ui, /*menu_bar,*/ viewport, workspace);
|
||||||
|
self.display_bboxes(ctx, ui, viewport, workspace);
|
||||||
self.display_navmeshes(ctx, ui, viewport, workspace);
|
self.display_navmeshes(ctx, ui, viewport, workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,6 +177,90 @@ impl Displayer {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn display_bboxes(
|
||||||
|
&mut self,
|
||||||
|
ctx: &egui::Context,
|
||||||
|
ui: &egui::Ui,
|
||||||
|
viewport: &Viewport,
|
||||||
|
workspace: &Workspace,
|
||||||
|
) {
|
||||||
|
for (_, joint) in workspace
|
||||||
|
.navmesher_board
|
||||||
|
.board()
|
||||||
|
.layout()
|
||||||
|
.joints()
|
||||||
|
.collection()
|
||||||
|
{
|
||||||
|
if workspace.appearance_panel.visible[joint.layer] {
|
||||||
|
ui.painter().rect_stroke(
|
||||||
|
egui::Rect {
|
||||||
|
min: egui::pos2(
|
||||||
|
joint.bbox().lower()[0] as f32,
|
||||||
|
joint.bbox().lower()[1] as f32,
|
||||||
|
),
|
||||||
|
max: egui::pos2(
|
||||||
|
joint.bbox().upper()[0] as f32,
|
||||||
|
joint.bbox().upper()[1] as f32,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
egui::CornerRadius::ZERO,
|
||||||
|
egui::Stroke::new(5.0, egui::Color32::GRAY),
|
||||||
|
egui::StrokeKind::Middle,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i, segment) in workspace
|
||||||
|
.navmesher_board
|
||||||
|
.board()
|
||||||
|
.layout()
|
||||||
|
.segments()
|
||||||
|
.collection()
|
||||||
|
{
|
||||||
|
if workspace.appearance_panel.visible[segment.layer] {
|
||||||
|
let endpoints = workspace
|
||||||
|
.navmesher_board
|
||||||
|
.board()
|
||||||
|
.layout()
|
||||||
|
.segment_endpoints(SegmentId::new(i));
|
||||||
|
|
||||||
|
ui.painter().rect_stroke(
|
||||||
|
egui::Rect::from_two_pos(
|
||||||
|
egui::pos2(endpoints[0][0] as f32, endpoints[0][1] as f32),
|
||||||
|
egui::pos2(endpoints[1][0] as f32, endpoints[1][1] as f32),
|
||||||
|
),
|
||||||
|
egui::CornerRadius::ZERO,
|
||||||
|
egui::Stroke::new(5.0, egui::Color32::GRAY),
|
||||||
|
egui::StrokeKind::Middle,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: vias.
|
||||||
|
|
||||||
|
for (i, polygon) in workspace
|
||||||
|
.navmesher_board
|
||||||
|
.board()
|
||||||
|
.layout()
|
||||||
|
.polygons()
|
||||||
|
.collection()
|
||||||
|
{
|
||||||
|
if workspace.appearance_panel.visible[polygon.layer] {
|
||||||
|
let bbox = polygon.bbox();
|
||||||
|
|
||||||
|
ui.painter().rect_stroke(
|
||||||
|
egui::Rect {
|
||||||
|
min: egui::pos2(bbox.lower()[0] as f32, bbox.lower()[1] as f32),
|
||||||
|
max: egui::pos2(bbox.upper()[0] as f32, bbox.upper()[1] as f32),
|
||||||
|
},
|
||||||
|
egui::CornerRadius::ZERO,
|
||||||
|
egui::Stroke::new(5.0, egui::Color32::GRAY),
|
||||||
|
egui::StrokeKind::Middle,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn display_navmeshes(
|
fn display_navmeshes(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &egui::Context,
|
ctx: &egui::Context,
|
||||||
|
|
@ -8,7 +8,7 @@ mod action;
|
||||||
mod actions;
|
mod actions;
|
||||||
mod app;
|
mod app;
|
||||||
mod appearance_panel;
|
mod appearance_panel;
|
||||||
mod displayer;
|
mod display;
|
||||||
mod menu_bar;
|
mod menu_bar;
|
||||||
mod translator;
|
mod translator;
|
||||||
mod viewport;
|
mod viewport;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use egui::Pos2;
|
use egui::Pos2;
|
||||||
|
|
||||||
use crate::{displayer::Displayer, workspace::Workspace};
|
use crate::{display::Display, workspace::Workspace};
|
||||||
|
|
||||||
pub struct Viewport {
|
pub struct Viewport {
|
||||||
pub scene_rect: egui::Rect,
|
pub scene_rect: egui::Rect,
|
||||||
|
|
@ -29,7 +29,7 @@ impl Viewport {
|
||||||
.zoom_range(0.00001..=10000.0)
|
.zoom_range(0.00001..=10000.0)
|
||||||
.show(ui, &mut scene_rect, |ui| {
|
.show(ui, &mut scene_rect, |ui| {
|
||||||
if let Some(ref workspace) = workspace {
|
if let Some(ref workspace) = workspace {
|
||||||
let mut displayer = Displayer::new();
|
let mut displayer = Display::new();
|
||||||
displayer.update(ctx, ui, &self, workspace);
|
displayer.update(ctx, ui, &self, workspace);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,8 @@ impl ApplyDelta<LayoutHalfDelta> for Layout {
|
||||||
|
|
||||||
let polygons_delta = Delta::with_removed_inserted(removed.polygons, inserted.polygons);
|
let polygons_delta = Delta::with_removed_inserted(removed.polygons, inserted.polygons);
|
||||||
self.polygons.apply_delta(&polygons_delta);
|
self.polygons.apply_delta(&polygons_delta);
|
||||||
|
|
||||||
|
// TODO R-trees.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -223,6 +225,8 @@ impl FlushDelta<LayoutHalfDelta> for Layout {
|
||||||
let (removed_vias, inserted_vias) = self.vias.flush_delta().dissolve();
|
let (removed_vias, inserted_vias) = self.vias.flush_delta().dissolve();
|
||||||
let (removed_polygons, inserted_polygons) = self.polygons.flush_delta().dissolve();
|
let (removed_polygons, inserted_polygons) = self.polygons.flush_delta().dissolve();
|
||||||
|
|
||||||
|
// TODO R-trees.
|
||||||
|
|
||||||
Delta::with_removed_inserted(
|
Delta::with_removed_inserted(
|
||||||
LayoutHalfDelta {
|
LayoutHalfDelta {
|
||||||
joints: removed_joints,
|
joints: removed_joints,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue