mirror of https://codeberg.org/topola/topola.git
feat(topola/specctra): Insert and display rectangular pins
This commit is contained in:
parent
c927ad281f
commit
4264d2c52d
|
|
@ -2,9 +2,8 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use egui::Pos2;
|
|
||||||
|
|
||||||
use crate::{viewport::Viewport, workspace::Workspace};
|
use crate::{viewport::Viewport, workspace::Workspace};
|
||||||
|
use topola::{Joint, Polygon};
|
||||||
|
|
||||||
pub struct Displayer {}
|
pub struct Displayer {}
|
||||||
|
|
||||||
|
|
@ -47,11 +46,47 @@ impl Displayer {
|
||||||
);
|
);
|
||||||
|
|
||||||
for (_, joint) in workspace.board.layout().joints().collection() {
|
for (_, joint) in workspace.board.layout().joints().collection() {
|
||||||
ui.painter().circle_filled(
|
self.paint_joint(ctx, ui, viewport, joint);
|
||||||
egui::Pos2::new(joint.position[0] as f32, joint.position[1] as f32),
|
}
|
||||||
joint.radius as f32,
|
|
||||||
egui::Color32::RED,
|
// 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),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,6 @@ mod navmesher;
|
||||||
mod specctra;
|
mod specctra;
|
||||||
|
|
||||||
pub use crate::board::Board;
|
pub use crate::board::Board;
|
||||||
|
pub use crate::layout::{
|
||||||
|
Joint, JointId, Layout, Polygon, PolygonId, Segment, SegmentId, Via, ViaId,
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,11 @@ use specctra::{
|
||||||
structure::{DsnFile, Shape},
|
structure::{DsnFile, Shape},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{board::Board, layout::Joint, math::Vector2};
|
use crate::{
|
||||||
|
board::Board,
|
||||||
|
layout::{Joint, Polygon},
|
||||||
|
math::Vector2,
|
||||||
|
};
|
||||||
|
|
||||||
impl Board {
|
impl Board {
|
||||||
pub fn from_specctra(dsn: DsnFile) -> Self {
|
pub fn from_specctra(dsn: DsnFile) -> Self {
|
||||||
|
|
@ -51,6 +55,17 @@ impl Board {
|
||||||
(circle.diameter / 2.0) as u64,
|
(circle.diameter / 2.0) as u64,
|
||||||
false,
|
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,
|
board: &mut Board,
|
||||||
place: PointWithRotation,
|
place: PointWithRotation,
|
||||||
pin: PointWithRotation,
|
pin: PointWithRotation,
|
||||||
|
|
@ -88,15 +103,15 @@ impl Board {
|
||||||
flip: bool,
|
flip: bool,
|
||||||
) {
|
) {
|
||||||
board.add_polygon(Polygon {
|
board.add_polygon(Polygon {
|
||||||
vertices: [
|
vertices: vec![
|
||||||
Self::pos(place, pin, x1, y1, flip),
|
Self::pos(place, pin, x1, y1, flip),
|
||||||
Self::pos(place, pin, x2, y1, flip),
|
Self::pos(place, pin, x2, y1, flip),
|
||||||
Self::pos(place, pin, x2, y2, flip),
|
Self::pos(place, pin, x2, y2, flip),
|
||||||
Self::pos(place, pin, x1, y2, flip),
|
Self::pos(place, pin, x1, y2, flip),
|
||||||
],
|
],
|
||||||
layer,
|
layer,
|
||||||
})
|
});
|
||||||
}*/
|
}
|
||||||
|
|
||||||
fn pos(
|
fn pos(
|
||||||
place: PointWithRotation,
|
place: PointWithRotation,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue