comments and inflate change
This commit is contained in:
parent
a185939953
commit
63203ee717
@ -12,6 +12,7 @@ pub fn draw_gerbers_(ui: &mut PlotUi, app: &mut Application) {
|
|||||||
for (file_name, (_, geo)) in &app.gerbers {
|
for (file_name, (_, geo)) in &app.gerbers {
|
||||||
let selected = &app.selection == file_name;
|
let selected = &app.selection == file_name;
|
||||||
|
|
||||||
|
// draw apertures
|
||||||
for geometry in geo.apertures.iter() {
|
for geometry in geo.apertures.iter() {
|
||||||
draw_on_plot_canvas(
|
draw_on_plot_canvas(
|
||||||
ui,
|
ui,
|
||||||
@ -20,6 +21,7 @@ pub fn draw_gerbers_(ui: &mut PlotUi, app: &mut Application) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw lines
|
||||||
for line in geo.paths.iter() {
|
for line in geo.paths.iter() {
|
||||||
draw_on_plot_canvas(
|
draw_on_plot_canvas(
|
||||||
ui,
|
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() {
|
for path in geo.outline_union.iter() {
|
||||||
let mut points = path
|
let mut points = path
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -30,6 +30,7 @@ impl From<GerberDoc> for Geometry {
|
|||||||
let mut path_container: Vec<LinePath> = Vec::new();
|
let mut path_container: Vec<LinePath> = Vec::new();
|
||||||
let mut added_apertures: Vec<Element> = Vec::new();
|
let mut added_apertures: Vec<Element> = Vec::new();
|
||||||
|
|
||||||
|
// create geometries by applying all gerber commands
|
||||||
for command in gerber.commands {
|
for command in gerber.commands {
|
||||||
println!("{command:?}");
|
println!("{command:?}");
|
||||||
match command {
|
match command {
|
||||||
@ -39,14 +40,15 @@ impl From<GerberDoc> for Geometry {
|
|||||||
match code {
|
match code {
|
||||||
DCode::Operation(op) => match op {
|
DCode::Operation(op) => match op {
|
||||||
Operation::Interpolate(coordinates, offset) => {
|
Operation::Interpolate(coordinates, offset) => {
|
||||||
|
// create line by interpolating from current position to new position
|
||||||
if selected_interpolation_mode == InterpolationMode::Linear
|
if selected_interpolation_mode == InterpolationMode::Linear
|
||||||
{
|
{
|
||||||
// self.add_draw_segment(coord);
|
// add current position as starting position if active path is empty (=> start new one)
|
||||||
let point = Point::try_from(&coordinates);
|
|
||||||
if active_path.is_empty() {
|
if active_path.is_empty() {
|
||||||
active_path.add(current_position);
|
active_path.add(current_position);
|
||||||
}
|
}
|
||||||
match point {
|
// add point (from gerber coordinates) to active path
|
||||||
|
match Point::try_from(&coordinates) {
|
||||||
Ok(point) => {
|
Ok(point) => {
|
||||||
active_path.add(point);
|
active_path.add(point);
|
||||||
}
|
}
|
||||||
@ -56,25 +58,29 @@ impl From<GerberDoc> for Geometry {
|
|||||||
// TODO
|
// TODO
|
||||||
// self.add_arc_segment(coord, offset.as_ref().expect(format!("No offset coord with 'Circular' state\r\n{:#?}", c).as_str()))
|
// 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);
|
Self::move_position(&coordinates, &mut current_position);
|
||||||
}
|
}
|
||||||
|
// move current coordinates to new position
|
||||||
Operation::Move(m) => {
|
Operation::Move(m) => {
|
||||||
debug!("Move to {:?}, create path.", &m);
|
// check if a aperture is selected and if it's circular
|
||||||
// self.create_path_from_data();
|
|
||||||
if let Some(Aperture::Circle(c)) =
|
if let Some(Aperture::Circle(c)) =
|
||||||
selected_aperture.as_ref()
|
selected_aperture.as_ref()
|
||||||
{
|
{
|
||||||
|
// check if a path is currently active
|
||||||
if !active_path.is_empty() {
|
if !active_path.is_empty() {
|
||||||
|
// finish active path if there is an active one
|
||||||
active_path.finalize(c.diameter);
|
active_path.finalize(c.diameter);
|
||||||
path_container.push(active_path);
|
path_container.push(active_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create new active path and move position tp current position
|
||||||
active_path = LinePath::new();
|
active_path = LinePath::new();
|
||||||
Geometry::move_position(&m, &mut current_position);
|
Self::move_position(&m, &mut current_position);
|
||||||
}
|
}
|
||||||
|
// add selected Aperture
|
||||||
Operation::Flash(f) => {
|
Operation::Flash(f) => {
|
||||||
// self.create_path_from_data();
|
|
||||||
Self::add_geometry(
|
Self::add_geometry(
|
||||||
&mut added_apertures,
|
&mut added_apertures,
|
||||||
¤t_position,
|
¤t_position,
|
||||||
@ -85,8 +91,8 @@ impl From<GerberDoc> for Geometry {
|
|||||||
Self::move_position(&f, &mut current_position);
|
Self::move_position(&f, &mut current_position);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// select an aperture
|
||||||
DCode::SelectAperture(ap) => {
|
DCode::SelectAperture(ap) => {
|
||||||
// self.create_path_from_data();
|
|
||||||
selected_aperture = Some(
|
selected_aperture = Some(
|
||||||
gerber
|
gerber
|
||||||
.apertures
|
.apertures
|
||||||
@ -121,6 +127,7 @@ impl From<GerberDoc> for Geometry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create empty path set
|
||||||
let mut result = clipper2::Paths::new(vec![]);
|
let mut result = clipper2::Paths::new(vec![]);
|
||||||
// if path_container.len() > 1 {
|
// if path_container.len() > 1 {
|
||||||
// let mut clipper = path_container[1]
|
// let mut clipper = path_container[1]
|
||||||
@ -149,15 +156,17 @@ impl From<GerberDoc> for Geometry {
|
|||||||
// .unwrap();
|
// .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);
|
let conductor_net = union_lines(&path_container);
|
||||||
|
|
||||||
for outline in &conductor_net {
|
// for outline in &conductor_net {
|
||||||
println!("{:?}", outline.included_points);
|
// println!("{:?}", outline.included_points);
|
||||||
geo.push(outline.outline.clone());
|
// 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) {
|
if let Some(geo) = union_with_apertures(&added_apertures, conductor_net) {
|
||||||
println!("Number of finalized net paths: {}", geo.len());
|
println!("Number of finalized net paths: {}", geo.len());
|
||||||
@ -175,7 +184,6 @@ impl From<GerberDoc> for Geometry {
|
|||||||
impl Geometry {
|
impl Geometry {
|
||||||
fn move_position(coord: &Coordinates, position: &mut Point) -> () {
|
fn move_position(coord: &Coordinates, position: &mut Point) -> () {
|
||||||
if let Ok(pos) = Point::try_from(coord) {
|
if let Ok(pos) = Point::try_from(coord) {
|
||||||
debug!("Moved position to {pos:?}");
|
|
||||||
*position = pos;
|
*position = pos;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -201,10 +209,10 @@ impl Geometry {
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
Aperture::Obround(o) => {
|
Aperture::Obround(o) => {
|
||||||
// error!("Unsupported Obround aperture:\r\n{:#?}", o);
|
|
||||||
geometries.push(Element::Obround(Obround::from_aperture_obround(o, target)));
|
geometries.push(Element::Obround(Obround::from_aperture_obround(o, target)));
|
||||||
}
|
}
|
||||||
Aperture::Polygon(p) => {
|
Aperture::Polygon(p) => {
|
||||||
|
// TODO add polygon
|
||||||
error!("Unsupported Polygon aperture:\r\n{:#?}", p);
|
error!("Unsupported Polygon aperture:\r\n{:#?}", p);
|
||||||
}
|
}
|
||||||
Aperture::Other(o) => {
|
Aperture::Other(o) => {
|
||||||
|
@ -30,7 +30,7 @@ pub fn union_lines(lines: &[LinePath]) -> Vec<ConductorNet> {
|
|||||||
// create list of intersecting lines
|
// create list of intersecting lines
|
||||||
let mut intersections = Vec::new();
|
let mut intersections = Vec::new();
|
||||||
let (p1, q1) = (line.points[0], line.points[1]);
|
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() {
|
for (i, l) in lines.iter().enumerate() {
|
||||||
if !l.is_empty() {
|
if !l.is_empty() {
|
||||||
// do not check for intersection with itself
|
// 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
|
// check for all lines in path
|
||||||
let intersect = l.points.windows(2).any(|w| {
|
let intersect = l.points.windows(2).any(|w| {
|
||||||
let (p2, q2) = (w[0], w[1]);
|
let (p2, q2) = (w[0], w[1]);
|
||||||
println!("LINE 2 {p2:?}, {q2:?}");
|
// println!("LINE 2 {p2:?}, {q2:?}");
|
||||||
do_intersect(p1, q1, p2, q2)
|
do_intersect(p1, q1, p2, q2)
|
||||||
});
|
});
|
||||||
println!("INTERSECTING: {intersect}");
|
// println!("INTERSECTING: {intersect}");
|
||||||
if intersect {
|
if intersect {
|
||||||
// let entry = intersection_map.entry(index).or_insert(Vec::new());
|
// let entry = intersection_map.entry(index).or_insert(Vec::new());
|
||||||
// entry.push(i);
|
// entry.push(i);
|
||||||
|
println!("INTERSECTING {:?} and {:?}", line.points, l.points);
|
||||||
intersections.push(i);
|
intersections.push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ impl OutlineGeometry {
|
|||||||
// inflate given path
|
// inflate given path
|
||||||
let outline = outline
|
let outline = outline
|
||||||
.clone()
|
.clone()
|
||||||
.inflate((stroke / 2.).into(), JoinType::Round, EndType::Polygon, 2.0)
|
.inflate((stroke / 2.).into(), JoinType::Miter, EndType::Polygon, 30.)
|
||||||
.simplify(0.01, false);
|
.simplify(0.01, false);
|
||||||
Self {
|
Self {
|
||||||
// path: outline,
|
// path: outline,
|
||||||
|
Loading…
Reference in New Issue
Block a user