mirror of https://codeberg.org/topola/topola.git
dsn: implement importing solid polygons
This commit is contained in:
parent
b04950cafc
commit
c141dfc735
|
|
@ -4,16 +4,20 @@ use geo::{point, Point, Rotate, Translate};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{dot::FixedDotWeight, seg::FixedSegWeight, Drawing},
|
drawing::{
|
||||||
|
dot::FixedDotWeight,
|
||||||
|
seg::FixedSegWeight,
|
||||||
|
zone::{SolidZoneWeight, ZoneIndex},
|
||||||
|
Drawing,
|
||||||
|
},
|
||||||
|
dsn::{
|
||||||
|
de,
|
||||||
|
rules::DsnRules,
|
||||||
|
structure::{self, DsnFile, Layer, Pcb, Shape},
|
||||||
|
},
|
||||||
math::Circle,
|
math::Circle,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
|
||||||
de,
|
|
||||||
rules::DsnRules,
|
|
||||||
structure::{self, DsnFile, Layer, Pcb, Shape},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum LoadingError {
|
pub enum LoadingError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
|
@ -153,7 +157,7 @@ impl DsnDesign {
|
||||||
&polygon.layer,
|
&polygon.layer,
|
||||||
place.side == "front",
|
place.side == "front",
|
||||||
);
|
);
|
||||||
Self::add_path(
|
Self::add_polygon(
|
||||||
&mut layout,
|
&mut layout,
|
||||||
(place.x as f64, place.y as f64).into(),
|
(place.x as f64, place.y as f64).into(),
|
||||||
place.rotation as f64,
|
place.rotation as f64,
|
||||||
|
|
@ -250,7 +254,7 @@ impl DsnDesign {
|
||||||
&polygon.layer,
|
&polygon.layer,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
Self::add_path(
|
Self::add_polygon(
|
||||||
&mut layout,
|
&mut layout,
|
||||||
(0.0, 0.0).into(),
|
(0.0, 0.0).into(),
|
||||||
0.0,
|
0.0,
|
||||||
|
|
@ -338,50 +342,68 @@ impl DsnDesign {
|
||||||
layer: u64,
|
layer: u64,
|
||||||
net: usize,
|
net: usize,
|
||||||
) {
|
) {
|
||||||
|
let zone = drawing.add_solid_zone(SolidZoneWeight {
|
||||||
|
layer,
|
||||||
|
maybe_net: Some(net),
|
||||||
|
});
|
||||||
|
|
||||||
// Corners.
|
// Corners.
|
||||||
let dot_1_1 = drawing
|
let dot_1_1 = drawing
|
||||||
.add_fixed_dot(FixedDotWeight {
|
.add_zone_fixed_dot(
|
||||||
circle: Circle {
|
FixedDotWeight {
|
||||||
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x1, y1),
|
circle: Circle {
|
||||||
r: 0.5,
|
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x1, y1),
|
||||||
|
r: 0.5,
|
||||||
|
},
|
||||||
|
layer,
|
||||||
|
maybe_net: Some(net),
|
||||||
},
|
},
|
||||||
layer,
|
zone.into(),
|
||||||
maybe_net: Some(net),
|
)
|
||||||
})
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let dot_2_1 = drawing
|
let dot_2_1 = drawing
|
||||||
.add_fixed_dot(FixedDotWeight {
|
.add_zone_fixed_dot(
|
||||||
circle: Circle {
|
FixedDotWeight {
|
||||||
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x2, y1),
|
circle: Circle {
|
||||||
r: 0.5,
|
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x2, y1),
|
||||||
|
r: 0.5,
|
||||||
|
},
|
||||||
|
layer,
|
||||||
|
maybe_net: Some(net),
|
||||||
},
|
},
|
||||||
layer,
|
zone.into(),
|
||||||
maybe_net: Some(net),
|
)
|
||||||
})
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let dot_2_2 = drawing
|
let dot_2_2 = drawing
|
||||||
.add_fixed_dot(FixedDotWeight {
|
.add_zone_fixed_dot(
|
||||||
circle: Circle {
|
FixedDotWeight {
|
||||||
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x2, y2),
|
circle: Circle {
|
||||||
r: 0.5,
|
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x2, y2),
|
||||||
|
r: 0.5,
|
||||||
|
},
|
||||||
|
layer,
|
||||||
|
maybe_net: Some(net),
|
||||||
},
|
},
|
||||||
layer,
|
zone.into(),
|
||||||
maybe_net: Some(net),
|
)
|
||||||
})
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let dot_1_2 = drawing
|
let dot_1_2 = drawing
|
||||||
.add_fixed_dot(FixedDotWeight {
|
.add_zone_fixed_dot(
|
||||||
circle: Circle {
|
FixedDotWeight {
|
||||||
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x1, y2),
|
circle: Circle {
|
||||||
r: 0.5,
|
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x1, y2),
|
||||||
|
r: 0.5,
|
||||||
|
},
|
||||||
|
layer,
|
||||||
|
maybe_net: Some(net),
|
||||||
},
|
},
|
||||||
layer,
|
zone.into(),
|
||||||
maybe_net: Some(net),
|
)
|
||||||
})
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// Sides.
|
// Sides.
|
||||||
drawing
|
drawing
|
||||||
.add_fixed_seg(
|
.add_zone_fixed_seg(
|
||||||
dot_1_1,
|
dot_1_1,
|
||||||
dot_2_1,
|
dot_2_1,
|
||||||
FixedSegWeight {
|
FixedSegWeight {
|
||||||
|
|
@ -389,10 +411,11 @@ impl DsnDesign {
|
||||||
layer,
|
layer,
|
||||||
maybe_net: Some(net),
|
maybe_net: Some(net),
|
||||||
},
|
},
|
||||||
|
zone.into(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
drawing
|
drawing
|
||||||
.add_fixed_seg(
|
.add_zone_fixed_seg(
|
||||||
dot_2_1,
|
dot_2_1,
|
||||||
dot_2_2,
|
dot_2_2,
|
||||||
FixedSegWeight {
|
FixedSegWeight {
|
||||||
|
|
@ -400,10 +423,11 @@ impl DsnDesign {
|
||||||
layer,
|
layer,
|
||||||
maybe_net: Some(net),
|
maybe_net: Some(net),
|
||||||
},
|
},
|
||||||
|
zone.into(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
drawing
|
drawing
|
||||||
.add_fixed_seg(
|
.add_zone_fixed_seg(
|
||||||
dot_2_2,
|
dot_2_2,
|
||||||
dot_1_2,
|
dot_1_2,
|
||||||
FixedSegWeight {
|
FixedSegWeight {
|
||||||
|
|
@ -411,10 +435,11 @@ impl DsnDesign {
|
||||||
layer,
|
layer,
|
||||||
maybe_net: Some(net),
|
maybe_net: Some(net),
|
||||||
},
|
},
|
||||||
|
zone.into(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
drawing
|
drawing
|
||||||
.add_fixed_seg(
|
.add_zone_fixed_seg(
|
||||||
dot_1_2,
|
dot_1_2,
|
||||||
dot_1_1,
|
dot_1_1,
|
||||||
FixedSegWeight {
|
FixedSegWeight {
|
||||||
|
|
@ -422,6 +447,7 @@ impl DsnDesign {
|
||||||
layer,
|
layer,
|
||||||
maybe_net: Some(net),
|
maybe_net: Some(net),
|
||||||
},
|
},
|
||||||
|
zone.into(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -494,6 +520,86 @@ impl DsnDesign {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_polygon(
|
||||||
|
drawing: &mut Drawing<DsnRules>,
|
||||||
|
place_pos: Point,
|
||||||
|
place_rot: f64,
|
||||||
|
pin_pos: Point,
|
||||||
|
pin_rot: f64,
|
||||||
|
coords: &Vec<structure::Point>,
|
||||||
|
width: f64,
|
||||||
|
layer: u64,
|
||||||
|
net: usize,
|
||||||
|
) {
|
||||||
|
let zone = drawing.add_solid_zone(SolidZoneWeight {
|
||||||
|
layer,
|
||||||
|
maybe_net: Some(net),
|
||||||
|
});
|
||||||
|
|
||||||
|
// add the first coordinate in the wire path as a dot and save its index
|
||||||
|
let mut prev_index = drawing
|
||||||
|
.add_zone_fixed_dot(
|
||||||
|
FixedDotWeight {
|
||||||
|
circle: Circle {
|
||||||
|
pos: Self::pos(
|
||||||
|
place_pos,
|
||||||
|
place_rot,
|
||||||
|
pin_pos,
|
||||||
|
pin_rot,
|
||||||
|
coords[0].x as f64,
|
||||||
|
coords[0].y as f64,
|
||||||
|
),
|
||||||
|
r: width / 2.0,
|
||||||
|
},
|
||||||
|
layer,
|
||||||
|
maybe_net: Some(net),
|
||||||
|
},
|
||||||
|
zone.into(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// iterate through path coords starting from the second
|
||||||
|
for coord in coords.iter().skip(1) {
|
||||||
|
let index = drawing
|
||||||
|
.add_zone_fixed_dot(
|
||||||
|
FixedDotWeight {
|
||||||
|
circle: Circle {
|
||||||
|
pos: Self::pos(
|
||||||
|
place_pos,
|
||||||
|
place_rot,
|
||||||
|
pin_pos,
|
||||||
|
pin_rot,
|
||||||
|
coord.x as f64,
|
||||||
|
coord.y as f64,
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
r: width / 2.0,
|
||||||
|
},
|
||||||
|
layer,
|
||||||
|
maybe_net: Some(net),
|
||||||
|
},
|
||||||
|
zone.into(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// add a seg between the current and previous coords
|
||||||
|
let _ = drawing
|
||||||
|
.add_zone_fixed_seg(
|
||||||
|
prev_index,
|
||||||
|
index,
|
||||||
|
FixedSegWeight {
|
||||||
|
width,
|
||||||
|
layer,
|
||||||
|
maybe_net: Some(net),
|
||||||
|
},
|
||||||
|
zone.into(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
prev_index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn pos(
|
fn pos(
|
||||||
place_pos: Point,
|
place_pos: Point,
|
||||||
place_rot: f64,
|
place_rot: f64,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue