diff options
author | adrian-bowyer <adrian-bowyer@cb376a5e-1013-0410-a455-b6b1f9ac8223> | 2010-08-28 16:23:44 +0000 |
---|---|---|
committer | adrian-bowyer <adrian-bowyer@cb376a5e-1013-0410-a455-b6b1f9ac8223> | 2010-08-28 16:23:44 +0000 |
commit | d4add41613c9da16d9797bd85f17e3e2d514c06a (patch) | |
tree | de228816210ebecc97318c57c4902e80f29258a2 | |
parent | 84d13e1890d6cccfd88a2d02615982d0c8a1bfb9 (diff) | |
download | reprap-backup-d4add41613c9da16d9797bd85f17e3e2d514c06a.tar.gz reprap-backup-d4add41613c9da16d9797bd85f17e3e2d514c06a.zip |
More messing around with the PCB code.
git-svn-id: https://reprap.svn.sourceforge.net/svnroot/reprap@3734 cb376a5e-1013-0410-a455-b6b1f9ac8223
7 files changed, 264 insertions, 118 deletions
diff --git a/trunk/reprap/host/src/org/reprap/Extruder.java b/trunk/reprap/host/src/org/reprap/Extruder.java index 49c14703..56de8ee8 100644 --- a/trunk/reprap/host/src/org/reprap/Extruder.java +++ b/trunk/reprap/host/src/org/reprap/Extruder.java @@ -500,6 +500,12 @@ public interface Extruder public double getExtrusionInfillWidth(); /** + * How high to lift above the surface for in-air movements + * @return + */ + public double getLift(); + + /** * * @return */ diff --git a/trunk/reprap/host/src/org/reprap/comms/GCodeReaderAndWriter.java b/trunk/reprap/host/src/org/reprap/comms/GCodeReaderAndWriter.java index f1330121..0f7f525f 100644 --- a/trunk/reprap/host/src/org/reprap/comms/GCodeReaderAndWriter.java +++ b/trunk/reprap/host/src/org/reprap/comms/GCodeReaderAndWriter.java @@ -165,6 +165,21 @@ public class GCodeReaderAndWriter public GCodeReaderAndWriter() { + init(); + } + + /** + * constructor for when we definitely want to send GCodes to a known file + * @param fos + */ + public GCodeReaderAndWriter(PrintStream fos) + { + init(); + fileOutStream = fos; + } + + private void init() + { resetReceived(); paused = false; iAmPaused = false; @@ -194,20 +209,6 @@ public class GCodeReaderAndWriter myPriority = Thread.currentThread().getPriority(); bufferThread = null; - -// if(serialOutStream != null) -// { -// bufferThread = new Thread() -// { -// public void run() -// { -// Thread.currentThread().setName("GCodeWriter() Buffer Thread"); -// bufferDeQueue(); -// } -// }; -// -// bufferThread.start(); -// } } diff --git a/trunk/reprap/host/src/org/reprap/devices/GenericExtruder.java b/trunk/reprap/host/src/org/reprap/devices/GenericExtruder.java index 7ec4dfdd..9e89bb7a 100644 --- a/trunk/reprap/host/src/org/reprap/devices/GenericExtruder.java +++ b/trunk/reprap/host/src/org/reprap/devices/GenericExtruder.java @@ -284,6 +284,11 @@ public abstract class GenericExtruder implements Extruder protected double extrusionDelayForLayer = 0; /** + * How high to move above the surface for non-extruding movements + */ + protected double lift = 0; + + /** * The number of milliseconds to wait before starting a hatch track */ protected double extrusionDelayForPolygon = 0; @@ -458,6 +463,7 @@ public abstract class GenericExtruder implements Extruder arcCompensationFactor = Preferences.loadGlobalDouble(prefName + "ArcCompensationFactor(0..)"); arcShortSides = Preferences.loadGlobalDouble(prefName + "ArcShortSides(0..)"); extrudeRatio = Preferences.loadGlobalDouble(prefName + "ExtrudeRatio(0..)"); + lift = Preferences.loadGlobalDouble(prefName + "Lift(mm)"); evenHatchDirection = Preferences.loadGlobalDouble(prefName + "EvenHatchDirection(degrees)"); oddHatchDirection = Preferences.loadGlobalDouble(prefName + "OddHatchDirection(degrees)"); @@ -1342,4 +1348,9 @@ public abstract class GenericExtruder implements Extruder return middleStart; } + public double getLift() + { + return lift; + } + } diff --git a/trunk/reprap/host/src/org/reprap/geometry/Producer.java b/trunk/reprap/host/src/org/reprap/geometry/Producer.java index 48f59f9a..12438afb 100644 --- a/trunk/reprap/host/src/org/reprap/geometry/Producer.java +++ b/trunk/reprap/host/src/org/reprap/geometry/Producer.java @@ -363,19 +363,19 @@ public class Producer { RrPolygonList fills = allSTLs.computeInfill(stl, layerRules); //, startNearHere); RrPolygonList borders = allSTLs.computeOutlines(stl, layerRules, fills, shield); RrPolygonList support = allSTLs.computeSupport(stl, layerRules); - borders = borders.nearEnds(startNearHere); + borders = borders.nearEnds(startNearHere, false); if(borders.size() > 0) { RrPolygon last = borders.polygon(borders.size() - 1); startNearHere = last.point(last.size() - 1); } - fills = fills.nearEnds(startNearHere); + fills = fills.nearEnds(startNearHere, false); if(fills.size() > 0) { RrPolygon last = fills.polygon(fills.size() - 1); startNearHere = last.point(last.size() - 1); } - support = support.nearEnds(startNearHere); + support = support.nearEnds(startNearHere, false); if(support.size() > 0) { RrPolygon last = support.polygon(support.size() - 1); diff --git a/trunk/reprap/host/src/org/reprap/geometry/polygons/RrPolygon.java b/trunk/reprap/host/src/org/reprap/geometry/polygons/RrPolygon.java index 0e47061b..e4ed9125 100644 --- a/trunk/reprap/host/src/org/reprap/geometry/polygons/RrPolygon.java +++ b/trunk/reprap/host/src/org/reprap/geometry/polygons/RrPolygon.java @@ -176,7 +176,7 @@ public class RrPolygon public RrPolygon(Attributes a, boolean c) { if(a == null) - System.err.println("RrPolygon(): null attributes!"); + Debug.e("RrPolygon(): null attributes!"); points = new ArrayList<Rr2Point>(); speeds = null; att = a; @@ -204,7 +204,7 @@ public class RrPolygon { if(speeds == null) { - System.err.println("Rr2Point.speed(int i): speeds null!"); + Debug.e("Rr2Point.speed(int i): speeds null!"); return 0; } return speeds.get(i).doubleValue(); @@ -277,7 +277,7 @@ public class RrPolygon public void add(Rr2Point p) { if(speeds != null) - System.err.println("Rr2Point.add(): adding a point to a polygon with its speeds set."); + Debug.e("Rr2Point.add(): adding a point to a polygon with its speeds set."); points.add(new Rr2Point(p)); box.expand(p); } @@ -290,7 +290,7 @@ public class RrPolygon public void add(int i, Rr2Point p) { if(speeds != null) - System.err.println("Rr2Point.add(): adding a point to a polygon with its speeds set."); + Debug.e("Rr2Point.add(): adding a point to a polygon with its speeds set."); points.add(i, new Rr2Point(p)); box.expand(p); } @@ -303,7 +303,7 @@ public class RrPolygon public void set(int i, Rr2Point p) { if(speeds != null) - System.err.println("Rr2Point.set(): adding a point to a polygon with its speeds set."); + Debug.e("Rr2Point.set(): adding a point to a polygon with its speeds set."); points.set(i, new Rr2Point(p)); box.expand(p); } @@ -317,7 +317,7 @@ public class RrPolygon public void add(int i, Rr2Point p, double s) { if(speeds == null) - System.err.println("Rr2Point.add(): adding a point and a speed to a polygon without its speeds set."); + Debug.e("Rr2Point.add(): adding a point and a speed to a polygon without its speeds set."); points.add(i, new Rr2Point(p)); speeds.add(i, s); box.expand(p); @@ -332,7 +332,7 @@ public class RrPolygon public void set(int i, Rr2Point p, double s) { if(speeds == null) - System.err.println("Rr2Point.set(): adding a point and a speed to a polygon without its speeds set."); + Debug.e("Rr2Point.set(): adding a point and a speed to a polygon without its speeds set."); points.set(i, new Rr2Point(p)); speeds.set(i, s); box.expand(p); @@ -382,12 +382,12 @@ public class RrPolygon if(speeds == null) { if(p.speeds != null) - System.err.println("Rr2Point.add(): adding a polygon to another polygon but discarding it's speeds."); + Debug.e("Rr2Point.add(): adding a polygon to another polygon but discarding it's speeds."); return; } if(p.speeds == null) { - System.err.println("Rr2Point.add(): adding a polygon to another polygon, but it has no needed speeds."); + Debug.e("Rr2Point.add(): adding a polygon to another polygon, but it has no needed speeds."); return; } for(int i = 0; i < p.size(); i++) @@ -465,7 +465,7 @@ public class RrPolygon { return newStart(rangen.nextInt(size())); // if(!isClosed()) -// System.err.println("RrPolygon.randomStart(): random-starting an open polygon!"); +// Debug.e("RrPolygon.randomStart(): random-starting an open polygon!"); // RrPolygon result = new RrPolygon(att, closed); // int i = rangen.nextInt(size()); // for(int j = 0; j < size(); j++) @@ -484,10 +484,10 @@ public class RrPolygon public RrPolygon newStart(int i) { if(!isClosed()) - System.err.println("RrPolygon.newStart(i): reordering an open polygon!"); + Debug.e("RrPolygon.newStart(i): reordering an open polygon!"); if(i < 0 || i >= size()) { - System.err.println("RrPolygon.newStart(i): dud index: " + i); + Debug.e("RrPolygon.newStart(i): dud index: " + i); return this; } RrPolygon result = new RrPolygon(att, closed); @@ -534,7 +534,7 @@ public class RrPolygon } } if(result < 0) - System.err.println("RrPolygon.nearestVertex(): no point found!"); + Debug.e("RrPolygon.nearestVertex(): no point found!"); return result; } @@ -558,7 +558,7 @@ public class RrPolygon } } if(result < 0) - System.err.println("RrPolygon.maximalVertex(): no point found!"); + Debug.e("RrPolygon.maximalVertex(): no point found!"); return result; } @@ -999,14 +999,14 @@ public class RrPolygon break; default: - System.err.println("RrPolygon.setSpeeds(): dud VelocityProfile flat value."); + Debug.e("RrPolygon.setSpeeds(): dud VelocityProfile flat value."); } } } if(speeds.size() != points.size()) - System.err.println("Speeds and points arrays different: " + speeds.size() + ", " + points.size()); + Debug.e("Speeds and points arrays different: " + speeds.size() + ", " + points.size()); } // **************************************************************************** @@ -1126,7 +1126,7 @@ public class RrPolygon a.set(1, k); } } else - System.err.println("clockWise(): not called for a triangle!"); + Debug.e("clockWise(): not called for a triangle!"); } @@ -1178,7 +1178,7 @@ public class RrPolygon { if(points.size() < 3) { - System.err.println("convexHull(): attempt to compute hull for " + points.size() + " points!"); + Debug.e("convexHull(): attempt to compute hull for " + points.size() + " points!"); return new ArrayList<Integer>(); } @@ -1241,7 +1241,7 @@ public class RrPolygon inConsideration.remove(corner); } else if(inConsideration.size() > 0) { - System.err.println("convexHull(): points left, but none included!"); + Debug.e("convexHull(): points left, but none included!"); return result; } @@ -1347,7 +1347,7 @@ public class RrPolygon List<Integer> ch = convexHull(a); if(ch.size() < 3) { - System.err.println("toCSGRecursive() - null convex hull: " + ch.size() + + Debug.e("toCSGRecursive() - null convex hull: " + ch.size() + " points."); return RrCSG.nothing(); } @@ -1429,7 +1429,7 @@ public class RrPolygon //RrRectangle b = copy.box.scale(1.1); //expression = expression.simplify(tolerance); //if(att == null) - // System.err.println("toCSG(): null attribute!"); + // Debug.e("toCSG(): null attribute!"); //RrCSGPolygon result = new RrCSGPolygon(expression, b, att); return expression; diff --git a/trunk/reprap/host/src/org/reprap/geometry/polygons/RrPolygonList.java b/trunk/reprap/host/src/org/reprap/geometry/polygons/RrPolygonList.java index 6e8bb7a2..08b50f86 100644 --- a/trunk/reprap/host/src/org/reprap/geometry/polygons/RrPolygonList.java +++ b/trunk/reprap/host/src/org/reprap/geometry/polygons/RrPolygonList.java @@ -61,6 +61,7 @@ import java.util.List; import org.reprap.Extruder; import org.reprap.geometry.LayerRules; +import org.reprap.utilities.Debug; /** * Small class to hold a polygon index and the index of a point within it @@ -72,22 +73,26 @@ class PolPoint private int pNear; private int pEnd; private int pg; + private double d2; private RrPolygon pol; - public PolPoint() - { + public PolPoint(int pnr, int pgn, RrPolygon poly, double s) + { + set(pnr, pgn, poly, s); } public int near() { return pNear; } public int end() { return pEnd; } public int pIndex() { return pg; } public RrPolygon polygon() { return pol; } + public double dist2() { return d2; } - public void set(int pnr, int pgn, RrPolygon poly) + public void set(int pnr, int pgn, RrPolygon poly, double s) { pNear = pnr; pg = pgn; pol = poly; + d2 = s; } private void midPoint(int i, int j) @@ -100,7 +105,7 @@ class PolPoint } if(i < 0 || i > pol.size() -1 || j < 0 || j > pol.size() -1) - System.err.println("RrPolygonList.midPoint(): i and/or j wrong: i = " + i + ", j = " + j); + Debug.e("RrPolygonList.midPoint(): i and/or j wrong: i = " + i + ", j = " + j); Rr2Point p = Rr2Point.add(pol.point(i), pol.point(j)); p = Rr2Point.mul(p, 0.5); @@ -282,7 +287,7 @@ class treeList { if(children == null) { - System.err.println("treeList: attempt to get child from null list!"); + Debug.e("treeList: attempt to get child from null list!"); return null; } return children.get(i); @@ -704,12 +709,12 @@ public class RrPolygonList /** * Re-order and (if need be) reverse the order of the polygons * in a list so the end of the first is near the start of the second and so on. - * This is a heuristic - it does not do a full traveling salesman... - * This deals with both open and closed polygons, but it does not allow closed ones to - * be re-ordered, even if that would give a shorter path. + * This is a heuristic - it does not do a full travelling salesman... + * This deals with both open and closed polygons, but it only allows closed ones to + * be re-ordered if free is true. * @return new ordered polygon list */ - public RrPolygonList nearEnds(Rr2Point startNearHere) + public RrPolygonList nearEnds(Rr2Point startNearHere, boolean free) { RrPolygonList r = new RrPolygonList(); if(size() <= 0) @@ -727,6 +732,7 @@ public class RrPolygonList double d = Double.POSITIVE_INFINITY; double d2; int near = -1; + int nearV = -1; Rr2Point e1; if(startNearHere != null) @@ -738,16 +744,32 @@ public class RrPolygonList if(d2 < d) { near = i; + nearV = -1; d = d2; neg = false; } - if(!r.polygon(i).isClosed()) + if(r.polygon(i).isClosed()) + { + if(free) + { + int nv = polygon(i).nearestVertex(startNearHere); + d2 = Rr2Point.dSquared(startNearHere, polygon(i).point(nv)); + if(d2 < d) + { + near = i; + nearV = nv; + d = d2; + neg = false; + } + } + } else { e1 = r.polygon(i).point(r.polygon(i).size() - 1); d2 = Rr2Point.dSquared(startNearHere, e1); if(d2 < d) { near = i; + nearV = -1; d = d2; neg = true; } @@ -756,11 +778,13 @@ public class RrPolygonList if(near < 0) { - System.err.println("RrPolygonList.nearEnds(): no nearest end found to start point!"); + Debug.e("RrPolygonList.nearEnds(): no nearest end found to start point!"); return r; } r.swap(0, near); + if(free && nearV >= 0) + set(0, polygon(0).newStart(nearV)); if(neg) r.negate(0); } @@ -780,33 +804,33 @@ public class RrPolygonList end = pgp.point(pgp.size() - 1); neg = false; near = -1; - int nearv = -1; + nearV = -1; d = Double.POSITIVE_INFINITY; for(i = pg+1; i < r.size(); i++) { pgp = r.polygon(i); e1 = pgp.point(0); -// if(pgp.isClosed()) -// { -// int nv = pgp.nearestVertex(e1); -// d2 = Rr2Point.dSquared(pgp.point(nv), e1); -// if(d2 < d) -// { -// near = i; -// d = d2; -// neg = false; -// nearv = nv; -// } -// } else -// { + if(pgp.isClosed() && free) + { + int nv = pgp.nearestVertex(e1); + d2 = Rr2Point.dSquared(pgp.point(nv), e1); + if(d2 < d) + { + near = i; + d = d2; + neg = false; + nearV = nv; + } + } else + { d2 = Rr2Point.dSquared(end, e1); if(d2 < d) { near = i; d = d2; neg = false; - nearv = -1; + nearV = -1; } e1 = pgp.point(pgp.size() - 1); @@ -816,14 +840,14 @@ public class RrPolygonList near = i; d = d2; neg = true && !pgp.isClosed(); - nearv = -1; + nearV = -1; } -// } + } } if(near < 0) { - System.err.println("RrPolygonList.nearEnds(): no nearest end found!"); + Debug.e("RrPolygonList.nearEnds(): no nearest end found!"); return r; } @@ -831,8 +855,8 @@ public class RrPolygonList r.swap(pg+1, near); if(neg) r.negate(pg+1); - if(nearv > 0) - r.set(pg+1, r.polygon(pg+1).newStart(nearv)); + if(nearV > 0) + r.set(pg+1, r.polygon(pg+1).newStart(nearV)); pg++; } @@ -882,12 +906,13 @@ public class RrPolygonList /** * Search a polygon list to find the nearest point on all the polygons within it - * to the point p. + * to the point p. If omit is non-negative, ignore that polygon in the search. * * @param p + * @param omit * @return */ - private PolPoint ppSearch(Rr2Point p) + private PolPoint ppSearch(Rr2Point p, int omit) { double d = Double.POSITIVE_INFINITY; PolPoint result = null; @@ -897,20 +922,24 @@ public class RrPolygonList for(int i = 0; i < size(); i++) { - RrPolygon pgon = polygon(i); - int n = pgon.nearestVertex(p); - double d2 = Rr2Point.dSquared(p, pgon.point(n)); - if(d2 < d) + if(i != omit) { - if(result == null) - result = new PolPoint(); - result.set(n, i, pgon); - d = d2; + RrPolygon pgon = polygon(i); + int n = pgon.nearestVertex(p); + double d2 = Rr2Point.dSquared(p, pgon.point(n)); + if(d2 < d) + { + if(result == null) + result = new PolPoint(n, i, pgon, d2); + else + result.set(n, i, pgon, d2); + d = d2; + } } } if(result == null) - System.err.println("RrPolygonList.ppSearch(): no point found!"); + Debug.e("RrPolygonList.ppSearch(): no point found!"); return result; } @@ -943,7 +972,7 @@ public class RrPolygonList outline = outline.newStart(outline.maximalVertex(l)); Rr2Point start = outline.point(0); - PolPoint pp = hatching.ppSearch(start); + PolPoint pp = hatching.ppSearch(start, -1); if(pp != null) { pp.findLongEnough(10, 30); @@ -1039,7 +1068,7 @@ public class RrPolygonList boolean b = (exp.value(p) <= 0); if (a != b) { - System.err.println("RrPolygonList:inside() - i is both inside and outside j!"); + Debug.e("RrPolygonList:inside() - i is both inside and outside j!"); // casting vote... p = polygon(i).point(polygon(i).size()/3); return exp.value(p) <= 0; @@ -1103,7 +1132,7 @@ public class RrPolygonList { treeList isList = universe.walkFind(i); if(isList == null) - System.err.println("RrPolygonList.resolveInsides() - can't find list for polygon " + i); + Debug.e("RrPolygonList.resolveInsides() - can't find list for polygon " + i); treeList parent = isList.getParent(); if(parent != null) { diff --git a/trunk/reprap/host/src/org/reprap/pcb/PCB.java b/trunk/reprap/host/src/org/reprap/pcb/PCB.java index 34f37097..6ee6207d 100644 --- a/trunk/reprap/host/src/org/reprap/pcb/PCB.java +++ b/trunk/reprap/host/src/org/reprap/pcb/PCB.java @@ -2,12 +2,17 @@ package org.reprap.pcb; import java.io.BufferedReader; import java.io.BufferedWriter; +import java.io.FileNotFoundException; +import java.io.PrintStream; import java.io.FileReader; import java.io.FileWriter; import java.io.File; +import java.util.Date; +import java.text.SimpleDateFormat; import org.reprap.Extruder; import org.reprap.Attributes; import org.reprap.geometry.polygons.*; +import org.reprap.comms.GCodeReaderAndWriter; //import java.io.IOException; @@ -16,7 +21,7 @@ public class PCB { GerberGCode gerberGcode; String[] splitline; boolean debug = false; - + RrRectangle bigBox; BufferedReader in; String line; String formatX = "23", formatY="23"; @@ -28,51 +33,161 @@ public class PCB { double penWidth = 0.7f; double offsetX=40; double offsetY=40; -// int XYFeedrate = 1000; -// int ZFeedrate = 70; -// double drawingHeight = 1.8f; -// double freemoveHeight = 3.8f;//1.7f; + File inputTracksAndPads; + File inputDrill; + File outputGCodes; + Extruder pcbPen; + RrPolygonList penPaths; + GCodeReaderAndWriter gcode; + /** * @param args */ - public void pcb(File inputFile, File inputDrill, File outputFile, Extruder pcbPen) { + public void pcb(File itp, File id, File og, Extruder pp) { // Config end - - + inputTracksAndPads = itp; + inputDrill = id; + outputGCodes = og; + pcbPen = pp; penWidth = pcbPen.getExtrusionSize(); System.out.println("Gerber RS274X to GCoder Converter for RepRap\n"); - System.out.println("Input: " + inputFile.getName()); - System.out.println("Output: " + outputFile.getName()+"\n"); + System.out.println("Input: " + inputTracksAndPads.getName()); + System.out.println("Output: " + outputGCodes.getName()+"\n"); System.out.println("Pen Width: " + penWidth + " mm"); System.out.println("Offset X: " + offsetX + " mm"); System.out.println("Offset Y: " + offsetY + " mm"); -// System.out.println("Drawing Height: " + drawingHeight + " mm"); -// System.out.println("Freemove Height: " + freemoveHeight + " mm\n"); + createBitmap(); + + penPaths = gerberGcode.getPolygons(); + + penPaths = penPaths.nearEnds(new Rr2Point(0, 0), true); + + writeGCodes(); + + System.out.println("GCode file generated succesfully !"); + } + + private void raisePen() + { + try { + gcode.queue("G1 F30; Z feedrate"); //FIXME! + gcode.queue("G1 Z" + pcbPen.getLift() + "; Z clearance height"); + gcode.queue("G1 F" + pcbPen.getSlowXYFeedrate() + "; XY feedrate"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void lowerPen() + { + try { + gcode.queue("G1 F30; Z feedrate"); //FIXME! + gcode.queue("G1 Z0; Z clearance height"); + gcode.queue("G1 F" + pcbPen.getSlowXYFeedrate() + "; XY feedrate"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void PCBHeader() + { + gcode.startRun(); + try + { + gcode.queue("; PCB GCode generated by RepRap Java Host Software"); + Date myDate = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd:HH-mm-ss"); + String myDateString = sdf.format(myDate); + gcode.queue("; Created: " + myDateString); + gcode.queue(";#!RECTANGLE: " + bigBox); + gcode.queue(";#!LAYER: 1/1"); + gcode.queue("G21 ;metric"); + gcode.queue("G90 ;absolute positioning"); + gcode.queue("M140 S0.0 ;set bed temperature and return"); + gcode.queue("T" + pcbPen.getPhysicalExtruderNumber() + "; select new extruder"); + //gcode.queue("M113; set extruder to use pot for PWM"); + gcode.queue("G28; go home"); + gcode.queue("G92 E0 ;zero the extruded length"); + raisePen(); + } catch (Exception e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void PCBFooter() + { + try + { + gcode.queue("M0 ; stop RepRap"); + } catch (Exception e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void polygonPlot(RrPolygon p) + { + if(p.size() <= 0) + return; + try { + gcode.queue("G1 X" + p.point(0).x() + " Y" + p.point(0).y() + "; move to polygon start"); + lowerPen(); + for(int i = 1; i < p.size(); i++) + gcode.queue("G1 X" + p.point(i).x() + " Y" + p.point(i).y() + "; draw line"); + gcode.queue("G1 X" + p.point(0).x() + " Y" + p.point(0).y() + "; draw back to polygon start"); + } catch (Exception e) { + e.printStackTrace(); + return; + } + raisePen(); + } + + private void writeGCodes() + { + try { + gcode = new GCodeReaderAndWriter(new PrintStream(outputGCodes)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return; + } + PCBHeader(); + for(int i = 0; i < penPaths.size(); i++) + polygonPlot(penPaths.polygon(i)); + PCBFooter(); + } + + private void createBitmap() + { gerberGcode = new GerberGCode(pcbPen, null, true); //, drawingHeight, freemoveHeight, XYFeedrate, ZFeedrate); - RrRectangle box = new RrRectangle(); + bigBox = new RrRectangle(); // processing Gerber file try { - in = new BufferedReader(new FileReader(inputFile)); + in = new BufferedReader(new FileReader(inputTracksAndPads)); while((line = in.readLine()) != null) { RrRectangle r = processLine(line, false); if(r != null) - box = RrRectangle.union(box, r); + bigBox = RrRectangle.union(bigBox, r); } if(debug) - System.out.println("Surrounding reactangle: " + box); + System.out.println("Surrounding reactangle: " + bigBox); in.close(); - in = new BufferedReader(new FileReader(inputFile)); + in = new BufferedReader(new FileReader(inputTracksAndPads)); - BooleanGrid pattern = new BooleanGrid(RrCSG.nothing(), box, new Attributes(null, null, null, pcbPen.getAppearance())); + BooleanGrid pattern = new BooleanGrid(RrCSG.nothing(), bigBox, new Attributes(null, null, null, pcbPen.getAppearance())); gerberGcode = new GerberGCode(pcbPen, pattern, true); @@ -85,32 +200,16 @@ public class PCB { { in = new BufferedReader(new FileReader(inputDrill)); gerberGcode = new GerberGCode(pcbPen, pattern, false); - gerberGcode.addCircleAperture(-1, 0.3); + gerberGcode.addCircleAperture(-1, 0.3); // Just mark drill centres with an 0.3mm disc while((line = in.readLine()) != null) { processLine(line, true); } } - - //System.out.println(gerberGcode.getGCode()); - -// BufferedWriter outfile; - -// outfile = new BufferedWriter(new FileWriter(outputFile)); -// outfile.write(gerberGcode.getPolygons()); -// outfile.close(); - - gerberGcode.getPolygons(); - - System.out.println("GCode file generated succesfully !"); - } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } - - - } private RrRectangle processLine(String line, boolean drill) |