use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class GcodeParserTest method autoLevelerProcessorSet.
@Test
public void autoLevelerProcessorSet() throws Exception {
System.out.println("autoLevelerProcessorSet");
GcodeParser gcp = new GcodeParser();
gcp.addCommandProcessor(new CommentProcessor());
gcp.addCommandProcessor(new ArcExpander(true, 0.1));
gcp.addCommandProcessor(new LineSplitter(1));
Position[][] grid = { { new Position(-5, -5, 0, MM), new Position(-5, 35, 0, MM) }, { new Position(35, -5, 0, MM), new Position(35, 35, 0, MM) } };
gcp.addCommandProcessor(new MeshLeveler(0, grid, Units.MM));
Path output = Files.createTempFile("autoleveler_processor_set_test.nc", "");
// Copy resource to temp file since my parser methods need it that way.
URL file = this.getClass().getClassLoader().getResource("./gcode/circle_test.nc");
File tempFile = File.createTempFile("temp", "file");
IOUtils.copy(file.openStream(), FileUtils.openOutputStream(tempFile));
GcodeParserUtils.processAndExport(gcp, tempFile, output.toFile());
GcodeStreamReader reader = new GcodeStreamReader(output.toFile());
file = this.getClass().getClassLoader().getResource("./gcode/circle_test.nc.processed");
Files.lines(Paths.get(file.toURI())).forEach((t) -> {
try {
GcodeCommand c = reader.getNextCommand();
if (c == null) {
Assert.fail("Reached end of gcode reader before end of expected commands.");
}
Assert.assertEquals(c.getCommandString(), t);
} catch (IOException ex) {
Assert.fail("Unexpected exception.");
}
});
assertEquals(1027, reader.getNumRows());
output.toFile().delete();
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class GcodeParserTest method spaceInAxisWord.
@Test
public void spaceInAxisWord() throws Exception {
List<GcodeMeta> metaList = GcodeParser.processCommand("G \t1 X-1Y - 0.\t5Z\n1 .0", 0, new GcodeState());
GcodeMeta meta = Iterables.getOnlyElement(metaList);
assertThat(meta.code).isEqualTo(G1);
assertThat(meta.state.currentPoint).isEqualTo(new Position(-1, -0.5, 1, MM));
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class ArcExpanderTest method modalsReturnedFirst.
@Test
public void modalsReturnedFirst() throws Exception {
System.out.println("arcExpandWithModals");
GcodeState state = new GcodeState();
state.currentPoint = new Position(0, 0, 0, MM);
state.plane = XY;
ArcExpander instance = new ArcExpander(true, 1);
List<String> result = instance.processCommand("G17 G20 G02 X5 Y0 R12 S1300", state);
assertThat(result.get(0)).isEqualTo("G17G20S1300");
assertThat(result).size().isGreaterThan(2);
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class ArcExpanderTest method expandArcG18.
@Test
public void expandArcG18() throws Exception {
System.out.println("expandArcG18");
GcodeState state = new GcodeState();
state.currentPoint = new Position(0, 0, -1, MM);
state.plane = ZX;
// ///////////////////////////////////////////////////////
for (double segmentLength = 0.1; segmentLength < 1; segmentLength += 0.1) {
ArcExpander instance = new ArcExpander(true, segmentLength);
// Half circle clockwise, Z-1 -> Z1, X0 -> X1 -> X0
String command = "G2 Z1 X0 R1";
List<String> result = instance.processCommand(command, state);
assertThat(result.size()).isEqualTo((int) Math.ceil(Math.PI / segmentLength));
verifyLines(new Position(0, 0, 0, MM), result, 1., new Position(0, 0, -1, MM), new Position(1, 0, 1, MM), state.plane);
// Half circle clockwise, Z-1 -> Z1, X0 -> X-1 -> X0
command = "G3 Z1 X0 R1";
result = instance.processCommand(command, state);
assertThat(result.size()).isEqualTo((int) Math.ceil(Math.PI / segmentLength));
verifyLines(new Position(0, 0, 0, MM), result, 1., new Position(-1, 0, -1, MM), new Position(0, 0, 1, MM), state.plane);
}
}
use of com.willwinder.universalgcodesender.model.Position in project Universal-G-Code-Sender by winder.
the class AutoLevelPreview method draw.
@Override
public void draw(GLAutoDrawable drawable, boolean idle, Point3d workCoord, Point3d objectMin, Point3d objectMax, double scaleFactor, Point3d mouseWorldCoordinates, Point3d rotation) {
// Don't draw something invalid.
if (positions == null || positions.isEmpty()) {
return;
}
Position first = Iterables.getFirst(positions, null);
Units unit = first.getUnits();
double objectX = objectMax.x - objectMin.x;
double objectY = objectMax.y - objectMin.y;
double diameter = Math.max(objectX * 0.005, objectY * 0.005);
double minx, miny, minz;
double maxx, maxy, maxz;
minx = maxx = first.x;
miny = maxy = first.y;
minz = maxz = first.z;
GL2 gl = drawable.getGL().getGL2();
gl.glPushMatrix();
// Scale inch to mm if needed
double scale = UnitUtils.scaleUnits(unit, Units.MM);
if (unit != Units.MM) {
gl.glScaled(scale, scale, scale);
}
// Balls indicating the probe start locations.
gl.glColor4fv(new float[] { 0.1f, 0.1f, 0.1f, 1.0f }, 0);
for (Position p : positions) {
gl.glPushMatrix();
gl.glTranslated(p.x, p.y, p.z);
glut.glutSolidSphere(diameter / scale, 7, 7);
// update min/max
minx = Math.min(minx, p.x);
maxx = Math.max(maxx, p.x);
miny = Math.min(miny, p.y);
maxz = Math.max(maxz, p.z);
minz = Math.min(minz, p.z);
maxy = Math.max(maxy, p.y);
gl.glPopMatrix();
}
// Outline of probe area
gl.glPushMatrix();
gl.glTranslated((minx + maxx) / 2, (miny + maxy) / 2, (minz + maxz) / 2);
gl.glScaled(maxx - minx, maxy - miny, maxz - minz);
gl.glColor4fv(new float[] { 0.3f, 0, 0, 0.1f }, 0);
glut.glutWireCube((float) 1.);
gl.glPopMatrix();
drawProbedSurface(gl);
gl.glPopMatrix();
}
Aggregations