comments and inflate change

This commit is contained in:
Larsiiii 2024-08-16 19:54:54 +02:00
parent a185939953
commit 63203ee717
4 changed files with 32 additions and 21 deletions

View File

@ -12,6 +12,7 @@ pub fn draw_gerbers_(ui: &mut PlotUi, app: &mut Application) {
for (file_name, (_, geo)) in &app.gerbers {
let selected = &app.selection == file_name;
// draw apertures
for geometry in geo.apertures.iter() {
draw_on_plot_canvas(
ui,
@ -20,6 +21,7 @@ pub fn draw_gerbers_(ui: &mut PlotUi, app: &mut Application) {
);
}
// draw lines
for line in geo.paths.iter() {
draw_on_plot_canvas(
ui,
@ -28,7 +30,7 @@ pub fn draw_gerbers_(ui: &mut PlotUi, app: &mut Application) {
);
}
// draw union path
// draw outline union path
for path in geo.outline_union.iter() {
let mut points = path
.iter()

View File

@ -30,6 +30,7 @@ impl From<GerberDoc> for Geometry {
let mut path_container: Vec<LinePath> = Vec::new();
let mut added_apertures: Vec<Element> = Vec::new();
// create geometries by applying all gerber commands
for command in gerber.commands {
println!("{command:?}");
match command {
@ -39,14 +40,15 @@ impl From<GerberDoc> for Geometry {
match code {
DCode::Operation(op) => match op {
Operation::Interpolate(coordinates, offset) => {
// create line by interpolating from current position to new position
if selected_interpolation_mode == InterpolationMode::Linear
{
// self.add_draw_segment(coord);
let point = Point::try_from(&coordinates);
// add current position as starting position if active path is empty (=> start new one)
if active_path.is_empty() {
active_path.add(current_position);
}
match point {
// add point (from gerber coordinates) to active path
match Point::try_from(&coordinates) {
Ok(point) => {
active_path.add(point);
}
@ -56,25 +58,29 @@ impl From<GerberDoc> for Geometry {
// TODO
// self.add_arc_segment(coord, offset.as_ref().expect(format!("No offset coord with 'Circular' state\r\n{:#?}", c).as_str()))
}
// move current coordinates to new position
Self::move_position(&coordinates, &mut current_position);
}
// move current coordinates to new position
Operation::Move(m) => {
debug!("Move to {:?}, create path.", &m);
// self.create_path_from_data();
// check if a aperture is selected and if it's circular
if let Some(Aperture::Circle(c)) =
selected_aperture.as_ref()
{
// check if a path is currently active
if !active_path.is_empty() {
// finish active path if there is an active one
active_path.finalize(c.diameter);
path_container.push(active_path);
}
}
// create new active path and move position tp current position
active_path = LinePath::new();
Geometry::move_position(&m, &mut current_position);
Self::move_position(&m, &mut current_position);
}
// add selected Aperture
Operation::Flash(f) => {
// self.create_path_from_data();
Self::add_geometry(
&mut added_apertures,
&current_position,
@ -85,8 +91,8 @@ impl From<GerberDoc> for Geometry {
Self::move_position(&f, &mut current_position);
}
},
// select an aperture
DCode::SelectAperture(ap) => {
// self.create_path_from_data();
selected_aperture = Some(
gerber
.apertures
@ -121,6 +127,7 @@ impl From<GerberDoc> for Geometry {
}
}
// create empty path set
let mut result = clipper2::Paths::new(vec![]);
// if path_container.len() > 1 {
// let mut clipper = path_container[1]
@ -149,15 +156,17 @@ impl From<GerberDoc> for Geometry {
// .unwrap();
// }
let mut geo = Paths::new(vec![]);
// let mut geo = Paths::new(vec![]);
// union all drawn lines into nets of conductors
let conductor_net = union_lines(&path_container);
for outline in &conductor_net {
println!("{:?}", outline.included_points);
geo.push(outline.outline.clone());
}
// for outline in &conductor_net {
// println!("{:?}", outline.included_points);
// geo.push(outline.outline.clone());
// }
println!("Number of conductor net paths: {}", geo.len());
// println!("Number of conductor net paths: {}", geo.len());
if let Some(geo) = union_with_apertures(&added_apertures, conductor_net) {
println!("Number of finalized net paths: {}", geo.len());
@ -175,7 +184,6 @@ impl From<GerberDoc> for Geometry {
impl Geometry {
fn move_position(coord: &Coordinates, position: &mut Point) -> () {
if let Ok(pos) = Point::try_from(coord) {
debug!("Moved position to {pos:?}");
*position = pos;
};
}
@ -201,10 +209,10 @@ impl Geometry {
)));
}
Aperture::Obround(o) => {
// error!("Unsupported Obround aperture:\r\n{:#?}", o);
geometries.push(Element::Obround(Obround::from_aperture_obround(o, target)));
}
Aperture::Polygon(p) => {
// TODO add polygon
error!("Unsupported Polygon aperture:\r\n{:#?}", p);
}
Aperture::Other(o) => {

View File

@ -30,7 +30,7 @@ pub fn union_lines(lines: &[LinePath]) -> Vec<ConductorNet> {
// create list of intersecting lines
let mut intersections = Vec::new();
let (p1, q1) = (line.points[0], line.points[1]);
println!("LINE 1 {p1:?}, {q1:?}");
// println!("LINE 1 {p1:?}, {q1:?}");
for (i, l) in lines.iter().enumerate() {
if !l.is_empty() {
// do not check for intersection with itself
@ -38,13 +38,14 @@ pub fn union_lines(lines: &[LinePath]) -> Vec<ConductorNet> {
// check for all lines in path
let intersect = l.points.windows(2).any(|w| {
let (p2, q2) = (w[0], w[1]);
println!("LINE 2 {p2:?}, {q2:?}");
// println!("LINE 2 {p2:?}, {q2:?}");
do_intersect(p1, q1, p2, q2)
});
println!("INTERSECTING: {intersect}");
// println!("INTERSECTING: {intersect}");
if intersect {
// let entry = intersection_map.entry(index).or_insert(Vec::new());
// entry.push(i);
println!("INTERSECTING {:?} and {:?}", line.points, l.points);
intersections.push(i);
}
}

View File

@ -38,7 +38,7 @@ impl OutlineGeometry {
// inflate given path
let outline = outline
.clone()
.inflate((stroke / 2.).into(), JoinType::Round, EndType::Polygon, 2.0)
.inflate((stroke / 2.).into(), JoinType::Miter, EndType::Polygon, 30.)
.simplify(0.01, false);
Self {
// path: outline,