diff --git a/README.md b/README.md index 92321185..f246074a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,15 @@ +Slightly Improved Version +========================= + +Based on blog post: +http://www.muonhunter.com/blog/installing-freerouting-on-kicad + +This build requires both +* javaws.jar +* jh.jar + +Fixes for modern Java Rectangle -> Rectangle2D usage. + FreeRouting =========== diff --git a/boardgraphics/CoordinateTransform.java b/boardgraphics/CoordinateTransform.java index 73afc792..d9435709 100644 --- a/boardgraphics/CoordinateTransform.java +++ b/boardgraphics/CoordinateTransform.java @@ -22,6 +22,7 @@ import java.awt.Dimension; import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; /** * Transformation function between the board and the screen coordinate systems. @@ -60,7 +61,8 @@ public CoordinateTransform(IntBox p_design_box, Dimension p_panel_bounds ) display_y_offset = scale_factor * design_box_with_offset.ll.y ; } - /** Copy constructor */ + /** Copy constructor + * @param p_coordinate_transform */ public CoordinateTransform(CoordinateTransform p_coordinate_transform) { this.screen_bounds = new Dimension(p_coordinate_transform.screen_bounds); @@ -175,7 +177,7 @@ public double board_to_screen_angle(double p_angle) * If the internal rotation is not a multiple of Pi/2, a bounding rectangle of the * rotated rectangular shape is returned. */ - public java.awt.Rectangle board_to_screen(IntBox p_box) + public Rectangle2D board_to_screen(IntBox p_box) { Point2D corner_1 = board_to_screen(p_box.ll.to_float()); Point2D corner_2 = board_to_screen(p_box.ur.to_float()); @@ -183,9 +185,9 @@ public java.awt.Rectangle board_to_screen(IntBox p_box) double ll_y = Math.min(corner_1.getY(), corner_2.getY()); double dx = Math.abs(corner_2.getX() - corner_1.getX()); double dy = Math.abs(corner_2.getY() - corner_1.getY()); - java.awt.Rectangle result = - new java.awt. Rectangle((int) Math.floor(ll_x), (int) Math.floor(ll_y), - (int) Math.ceil(dx), (int) Math.ceil(dy)); + Rectangle2D result = + new Rectangle2D.Double(Math.floor(ll_x), Math.floor(ll_y), + Math.ceil(dx), Math.ceil(dy)); return result; } @@ -194,7 +196,7 @@ public java.awt.Rectangle board_to_screen(IntBox p_box) * If the internal rotation is not a multiple of Pi/2, a bounding box of the * rotated rectangular shape is returned. */ - public IntBox screen_to_board(java.awt.Rectangle p_rect) + public IntBox screen_to_board(Rectangle2D p_rect) { FloatPoint corner_1 = screen_to_board(new Point2D.Double(p_rect.getX(), p_rect.getY())); FloatPoint corner_2 = screen_to_board(new Point2D.Double(p_rect.getX() + p_rect.getWidth(), @@ -296,4 +298,5 @@ public int get_90_degree_rotation() private double rotation = 0; private FloatPoint rotation_pole; + } \ No newline at end of file diff --git a/boardgraphics/GraphicsContext.java b/boardgraphics/GraphicsContext.java index 87e844c6..3fef5c8d 100644 --- a/boardgraphics/GraphicsContext.java +++ b/boardgraphics/GraphicsContext.java @@ -32,7 +32,6 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Polygon; -import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.geom.Ellipse2D; import java.awt.geom.GeneralPath; @@ -127,7 +126,7 @@ public void draw(FloatPoint[] p_points, double p_half_width, Color p_color, Grap return; } Graphics2D g2 = (Graphics2D)p_g; - Rectangle clip_shape = (Rectangle)p_g.getClip() ; + Rectangle2D clip_shape = (Rectangle2D)p_g.getClip() ; // the class member update_box cannot be used here, because // the dirty rectangle is internally enlarged by the system. // Therefore we can not improve the performance by using an @@ -270,7 +269,7 @@ public void fill_circle(Circle p_circle, Graphics p_g, Color p_color, double p_t } Point2D center = coordinate_transform.board_to_screen(p_circle.center.to_float()); double radius = coordinate_transform.board_to_screen(p_circle.radius); - if (!point_near_rectangle(center.getX(), center.getY(), (Rectangle)p_g.getClip(), radius)) + if (!point_near_rectangle(center.getX(), center.getY(), (Rectangle2D)p_g.getClip(), radius)) { return; } @@ -310,7 +309,7 @@ public void fill_ellipse_arr(Ellipse [] p_ellipse_arr, Graphics p_g, Color p_co { Point2D center = coordinate_transform.board_to_screen(curr_ellipse.center); double bigger_radius = coordinate_transform.board_to_screen(curr_ellipse.bigger_radius); - if (!point_near_rectangle(center.getX(), center.getY(), (Rectangle)p_g.getClip(), bigger_radius)) + if (!point_near_rectangle(center.getX(), center.getY(), (Rectangle2D)p_g.getClip(), bigger_radius)) { continue; } @@ -334,21 +333,21 @@ public void fill_ellipse_arr(Ellipse [] p_ellipse_arr, Graphics p_g, Color p_co /** * Checks, if the distance of the point with coordinates p_x, p_y to p_rect ist at most p_dist. */ - private boolean point_near_rectangle(double p_x, double p_y, Rectangle p_rect, double p_dist) + private boolean point_near_rectangle(double p_x, double p_y, Rectangle2D p_rect, double p_dist) { - if (p_x < p_rect.x - p_dist) + if (p_x < p_rect.getX() - p_dist) { return false; } - if (p_y < p_rect.y - p_dist) + if (p_y < p_rect.getY() - p_dist) { return false; } - if (p_x > p_rect.x + p_rect.width + p_dist) + if (p_x > p_rect.getX() + p_rect.getWidth() + p_dist) { return false; } - if (p_y > p_rect.y + p_rect.height + p_dist) + if (p_y > p_rect.getY() + p_rect.getHeight() + p_dist) { return false; } @@ -429,7 +428,7 @@ public void fill_area(Area p_area, Graphics p_g, Color p_color, double p_translu System.out.println("GraphicsContext.fill_area: shape not bounded"); return; } - Rectangle clip_shape = (Rectangle)p_g.getClip() ; + Rectangle2D clip_shape = (Rectangle2D)p_g.getClip() ; IntBox clip_box = coordinate_transform.screen_to_board(clip_shape); if (!border.bounding_box().intersects(clip_box)) { @@ -665,7 +664,7 @@ public Point2D get_design_center() /** * Returns the bounding box of the design in screen coordinates. */ - public java.awt.Rectangle get_design_bounds() + public Rectangle2D get_design_bounds() { return coordinate_transform.board_to_screen(coordinate_transform.design_box); } diff --git a/gui/BoardFrame.java b/gui/BoardFrame.java index 49160cf3..22013b37 100644 --- a/gui/BoardFrame.java +++ b/gui/BoardFrame.java @@ -27,6 +27,7 @@ import board.BoardObservers; import designformats.specctra.DsnFile; +import java.awt.Rectangle; /** * @@ -422,8 +423,8 @@ java.awt.Point absolute_panel_location() public void zoom_all() { board_panel.board_handling.adjust_design_bounds(); - java.awt.Rectangle display_rect = board_panel.get_viewport_bounds(); - java.awt.Rectangle design_bounds = board_panel.board_handling.graphics_context.get_design_bounds(); + Rectangle display_rect = board_panel.get_viewport_bounds().getBounds(); + Rectangle design_bounds = board_panel.board_handling.graphics_context.get_design_bounds().getBounds(); double width_factor = display_rect.getWidth() /design_bounds.getWidth(); double height_factor = display_rect.getHeight() /design_bounds.getHeight(); double zoom_factor = Math.min(width_factor, height_factor); diff --git a/interactive/BoardHandling.java b/interactive/BoardHandling.java index c0d58f7c..0a228f40 100644 --- a/interactive/BoardHandling.java +++ b/interactive/BoardHandling.java @@ -50,6 +50,7 @@ import board.TestLevel; import designformats.specctra.DsnFile; +import java.awt.geom.Rectangle2D; /** * @@ -673,15 +674,15 @@ public void repaint() /** * Repaints a rectangle of board panel on the screen. */ - public void repaint(Rectangle p_rect) + public void repaint(Rectangle2D p_rect) { if (this.paint_immediately) { - panel.paintImmediately(p_rect); + panel.paintImmediately(p_rect.getBounds()); } else { - panel.repaint(p_rect); + panel.repaint(p_rect.getBounds()); } } @@ -1661,13 +1662,13 @@ public void start_adding_hole(Point2D p_point) * Gets a surrounding rectangle of the area, where an update of the * graphics is needed caused by the previous interactive actions. */ - Rectangle get_graphics_update_rectangle() + Rectangle2D get_graphics_update_rectangle() { - Rectangle result; + Rectangle2D result; IntBox update_box = board.get_graphics_update_box(); if (update_box == null || update_box.is_empty()) { - result = new Rectangle(0, 0, 0, 0); + result = new Rectangle2D.Double(0, 0, 0, 0); } else { diff --git a/javaws.jar b/javaws.jar new file mode 100644 index 00000000..44201bfd Binary files /dev/null and b/javaws.jar differ diff --git a/jh.jar b/jh.jar new file mode 100644 index 00000000..185d9422 Binary files /dev/null and b/jh.jar differ