diff --git a/topola-egui/src/displayer.rs b/topola-egui/src/displayer.rs index b051bcc..5ac4979 100644 --- a/topola-egui/src/displayer.rs +++ b/topola-egui/src/displayer.rs @@ -2,9 +2,8 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -use egui::Pos2; - use crate::{viewport::Viewport, workspace::Workspace}; +use topola::{Joint, Polygon}; pub struct Displayer {} @@ -47,11 +46,47 @@ impl Displayer { ); for (_, joint) in workspace.board.layout().joints().collection() { - ui.painter().circle_filled( - egui::Pos2::new(joint.position[0] as f32, joint.position[1] as f32), - joint.radius as f32, - egui::Color32::RED, - ); + self.paint_joint(ctx, ui, viewport, joint); + } + + // TODO. + + for (_, polygon) in workspace.board.layout().polygons().collection() { + self.paint_polygon(ctx, ui, viewport, polygon); } } + + fn paint_joint( + &mut self, + ctx: &egui::Context, + ui: &egui::Ui, + viewport: &Viewport, + joint: &Joint, + ) { + ui.painter().circle_filled( + egui::Pos2::new(joint.position[0] as f32, joint.position[1] as f32), + joint.radius as f32, + egui::Color32::RED, + ); + } + + fn paint_polygon( + &mut self, + ctx: &egui::Context, + ui: &egui::Ui, + viewport: &Viewport, + polygon: &Polygon, + ) { + let points: Vec = polygon + .vertices + .iter() + .map(|v| egui::pos2(v[0] as f32, v[1] as f32)) + .collect(); + + ui.painter().add(egui::Shape::convex_polygon( + points, + egui::Color32::RED, + egui::Stroke::new(5.0 / viewport.scale_factor(), egui::Color32::RED), + )); + } } diff --git a/topola/src/lib.rs b/topola/src/lib.rs index 8e19d70..0fc6f4b 100644 --- a/topola/src/lib.rs +++ b/topola/src/lib.rs @@ -9,3 +9,6 @@ mod navmesher; mod specctra; pub use crate::board::Board; +pub use crate::layout::{ + Joint, JointId, Layout, Polygon, PolygonId, Segment, SegmentId, Via, ViaId, +}; diff --git a/topola/src/specctra.rs b/topola/src/specctra.rs index 6de81f5..daba450 100644 --- a/topola/src/specctra.rs +++ b/topola/src/specctra.rs @@ -7,7 +7,11 @@ use specctra::{ structure::{DsnFile, Shape}, }; -use crate::{board::Board, layout::Joint, math::Vector2}; +use crate::{ + board::Board, + layout::{Joint, Polygon}, + math::Vector2, +}; impl Board { pub fn from_specctra(dsn: DsnFile) -> Self { @@ -51,6 +55,17 @@ impl Board { (circle.diameter / 2.0) as u64, false, ), + Shape::Rect(rect) => Self::place_rect( + &mut board, + place.point_with_rotation(), + pin.point_with_rotation(), + rect.x1, + rect.y1, + rect.x2, + rect.y2, + 0, + false, + ), _ => (), } } @@ -76,7 +91,7 @@ impl Board { }); } - /*pub fn place_rect( + pub fn place_rect( board: &mut Board, place: PointWithRotation, pin: PointWithRotation, @@ -88,15 +103,15 @@ impl Board { flip: bool, ) { board.add_polygon(Polygon { - vertices: [ + vertices: vec![ Self::pos(place, pin, x1, y1, flip), Self::pos(place, pin, x2, y1, flip), Self::pos(place, pin, x2, y2, flip), Self::pos(place, pin, x1, y2, flip), ], layer, - }) - }*/ + }); + } fn pos( place: PointWithRotation,