feat(topola/specctra): Insert and display rectangular pins

This commit is contained in:
Mikolaj Wielgus 2026-03-10 13:48:40 +01:00
parent c927ad281f
commit 4264d2c52d
3 changed files with 65 additions and 12 deletions

View File

@ -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<egui::Pos2> = 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),
));
}
}

View File

@ -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,
};

View File

@ -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,