use of com.willwinder.universalgcodesender.gcode.util.PlaneFormatter in project Universal-G-Code-Sender by winder.
the class GcodeParser method addArcPointSegment.
/**
* Create a PointSegment representing the arc command.
*/
private static PointSegment addArcPointSegment(Position nextPoint, boolean clockwise, List<String> args, int line, GcodeState state) {
if (nextPoint == null) {
return null;
}
PointSegment ps = new PointSegment(nextPoint, line);
Position center = GcodePreprocessorUtils.updateCenterWithCommand(args, state.currentPoint, nextPoint, state.inAbsoluteIJKMode, clockwise, new PlaneFormatter(state.plane));
double radius = GcodePreprocessorUtils.parseCoord(args, 'R');
// Calculate radius if necessary.
if (Double.isNaN(radius)) {
radius = Math.sqrt(Math.pow(state.currentPoint.x - center.x, 2.0) + Math.pow(state.currentPoint.y - center.y, 2.0));
}
ps.setIsMetric(state.isMetric);
ps.setArcCenter(center);
ps.setIsArc(true);
ps.setRadius(radius);
ps.setIsClockwise(clockwise);
ps.setPlaneState(state.plane);
// Save off the endpoint.
state.currentPoint = nextPoint;
return ps;
}
use of com.willwinder.universalgcodesender.gcode.util.PlaneFormatter in project Universal-G-Code-Sender by winder.
the class GcodeViewParse method addLinesFromPointSegment.
/**
* Turns a point segment into one or more LineSegment. Arcs are expanded.
* Keeps track of the minimum and maximum x/y/z locations.
*/
private List<LineSegment> addLinesFromPointSegment(final Position start, final PointSegment endSegment, double arcSegmentLength, List<LineSegment> ret) {
// For a line segment list ALL arcs must be converted to lines.
double minArcLength = 0;
LineSegment ls;
endSegment.convertToMetric();
Position end = new Position(endSegment.point());
// start is null for the first iteration.
if (start != null) {
// Expand arc for graphics.
if (endSegment.isArc()) {
List<Position> points = GcodePreprocessorUtils.generatePointsAlongArcBDring(start, end, endSegment.center(), endSegment.isClockwise(), endSegment.getRadius(), minArcLength, arcSegmentLength, new PlaneFormatter(endSegment.getPlaneState()));
// Create line segments from points.
if (points != null) {
Position startPoint = start;
for (Position nextPoint : points) {
ls = new LineSegment(startPoint, nextPoint, endSegment.getLineNumber());
ls.setIsArc(endSegment.isArc());
ls.setIsFastTraverse(endSegment.isFastTraverse());
ls.setIsZMovement(endSegment.isZMovement());
this.testExtremes(nextPoint);
ret.add(ls);
startPoint = nextPoint;
}
}
// Line
} else {
ls = new LineSegment(start, end, endSegment.getLineNumber());
ls.setIsArc(endSegment.isArc());
ls.setIsFastTraverse(endSegment.isFastTraverse());
ls.setIsZMovement(endSegment.isZMovement());
this.testExtremes(end);
ret.add(ls);
}
}
return ret;
}
use of com.willwinder.universalgcodesender.gcode.util.PlaneFormatter in project Universal-G-Code-Sender by winder.
the class ArcExpander method processCommand.
@Override
public List<String> processCommand(String command, GcodeState state) throws GcodeParserException {
if (state.currentPoint == null)
throw new GcodeParserException(Localization.getString("parser.processor.arc.start-error"));
List<String> results = new ArrayList<>();
List<GcodeMeta> commands = GcodeParser.processCommand(command, 0, state);
// If this is not an arc, there is nothing to do.
Code c = hasArcCommand(commands);
if (c == null) {
return Collections.singletonList(command);
}
SplitCommand sc = GcodePreprocessorUtils.extractMotion(c, command);
if (sc.remainder.length() > 0) {
results.add(sc.remainder);
}
GcodeMeta arcMeta = Iterables.getLast(commands);
PointSegment ps = arcMeta.point;
Position start = state.currentPoint;
Position end = arcMeta.point.point();
List<Position> points = GcodePreprocessorUtils.generatePointsAlongArcBDring(start, end, ps.center(), ps.isClockwise(), ps.getRadius(), 0, this.length, new PlaneFormatter(ps.getPlaneState()));
// That function returns the first and last points. Exclude the first
// point because the previous gcode command ends there already.
points.remove(0);
if (convertToLines) {
// Tack the speed onto the first line segment in case the arc also
// changed the feed value.
String feed = "F" + arcMeta.point.getSpeed();
for (Position point : points) {
results.add(GcodePreprocessorUtils.generateLineFromPoints(G1, start, point, state.inAbsoluteMode, df) + feed);
start = point;
feed = "";
}
} else {
// TODO: Generate arc segments.
throw new UnsupportedOperationException("I have not implemented this.");
}
return results;
}
Aggregations