Search in sources :

Example 26 with PartialPosition

use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.

the class TinyGControllerTest method jogMachineToWhenUsingInchesShouldConvertCoordinates.

@Test
public void jogMachineToWhenUsingInchesShouldConvertCoordinates() throws Exception {
    // Given
    when(communicator.isConnected()).thenReturn(true);
    // Simulate that the machine is running in inches
    controller.getCurrentGcodeState().units = Code.G20;
    // When
    InOrder orderVerifier = inOrder(communicator);
    controller.jogMachineTo(new PartialPosition(1.0, 2.0, 3.0, UnitUtils.Units.MM), 1000);
    // Then
    orderVerifier.verify(communicator, times(1)).queueCommand(any(GcodeCommand.class));
    orderVerifier.verify(communicator).streamCommands();
    GcodeCommand command = queueCommandArgumentCaptor.getAllValues().get(0);
    assertEquals("G20G90G1X0.039Y0.079Z0.118F39.37", command.getCommandString());
    assertTrue(command.isGenerated());
    assertTrue(command.isTemporaryParserModalChange());
}
Also used : InOrder(org.mockito.InOrder) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Test(org.junit.Test)

Example 27 with PartialPosition

use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.

the class GcodeUtilsTest method generateMoveToCommand.

@Test
public void generateMoveToCommand() {
    String result = GcodeUtils.generateMoveToCommand("G90", new PartialPosition(1.0, 2.0, 3.1, UnitUtils.Units.MM), 1000.1);
    assertEquals("G21G90X1Y2Z3.1F1000.1", result);
    result = GcodeUtils.generateMoveToCommand("G90", new PartialPosition(-1.0, -2.0, -3.1, UnitUtils.Units.MM), 1000.1);
    assertEquals("G21G90X-1Y-2Z-3.1F1000.1", result);
    result = GcodeUtils.generateMoveToCommand("G90", new PartialPosition(-1.0, -2.0, -3.1, UnitUtils.Units.INCH), 10000);
    assertEquals("G20G90X-1Y-2Z-3.1F10000", result);
    result = GcodeUtils.generateMoveToCommand("G90", new PartialPosition(-1.0, -2.0, -3.1, UnitUtils.Units.INCH), 0);
    assertEquals("G20G90X-1Y-2Z-3.1", result);
    result = GcodeUtils.generateMoveToCommand("G90", new PartialPosition(-1.0, -2.0, -3.1, UnitUtils.Units.INCH), -10);
    assertEquals("G20G90X-1Y-2Z-3.1", result);
    result = GcodeUtils.generateMoveToCommand("G90G1", new PartialPosition(-1.0, -2.0, -3.1, UnitUtils.Units.INCH), -10);
    assertEquals("G20G90G1X-1Y-2Z-3.1", result);
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Test(org.junit.Test)

Example 28 with PartialPosition

use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.

the class AbstractRotateAction method getCenter.

private Position getCenter(File gcodeFile) throws IOException, GcodeParserException {
    List<LineSegment> lineSegments = parseGcodeLinesFromFile(gcodeFile);
    // We only care about carving motion, filter those commands out
    List<PartialPosition> pointList = lineSegments.parallelStream().filter(lineSegment -> !lineSegment.isFastTraverse()).flatMap(lineSegment -> {
        // We map both the start and end points in MM
        PartialPosition start = PartialPosition.from(lineSegment.getStart());
        PartialPosition end = PartialPosition.from(lineSegment.getEnd());
        return Stream.of(start, end);
    }).distinct().collect(Collectors.toList());
    return MathUtils.getCenter(pointList);
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) ControllerStateEvent(com.willwinder.universalgcodesender.model.events.ControllerStateEvent) com.willwinder.universalgcodesender.utils(com.willwinder.universalgcodesender.utils) BackendAPI(com.willwinder.universalgcodesender.model.BackendAPI) UGSEvent(com.willwinder.universalgcodesender.model.UGSEvent) UGSEventListener(com.willwinder.universalgcodesender.listeners.UGSEventListener) GcodeViewParse(com.willwinder.universalgcodesender.visualizer.GcodeViewParse) HelpCtx(org.openide.util.HelpCtx) RotateProcessor(com.willwinder.universalgcodesender.gcode.processors.RotateProcessor) GcodeParserException(com.willwinder.universalgcodesender.gcode.util.GcodeParserException) CentralLookup(com.willwinder.ugs.nbp.lib.lookup.CentralLookup) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Node(org.openide.nodes.Node) VisualizerUtils(com.willwinder.universalgcodesender.visualizer.VisualizerUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) GcodeDataObject(com.willwinder.ugs.nbp.editor.GcodeDataObject) File(java.io.File) FileStateEvent(com.willwinder.universalgcodesender.model.events.FileStateEvent) LoaderDialogHelper(com.willwinder.universalgcodesender.uielements.helpers.LoaderDialogHelper) CookieAction(org.openide.util.actions.CookieAction) java.awt(java.awt) List(java.util.List) Stream(java.util.stream.Stream) FileState(com.willwinder.universalgcodesender.model.events.FileState) LineSegment(com.willwinder.universalgcodesender.visualizer.LineSegment) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) LineSegment(com.willwinder.universalgcodesender.visualizer.LineSegment)

Example 29 with PartialPosition

use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.

the class MathUtilsTest method orientationWithPointsCollinear.

@Test
public void orientationWithPointsCollinear() {
    PartialPosition p1 = new PartialPosition(0d, 0d, UnitUtils.Units.MM);
    PartialPosition p2 = new PartialPosition(1d, 1d, UnitUtils.Units.MM);
    PartialPosition p3 = new PartialPosition(2d, 2d, UnitUtils.Units.MM);
    int orientation = MathUtils.orientation(p1, p2, p3);
    assertEquals(MathUtils.COLLINEAR, orientation);
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Test(org.junit.Test)

Example 30 with PartialPosition

use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.

the class MathUtilsTest method createConvexHullShouldRemoveInternalPoints.

@Test
public void createConvexHullShouldRemoveInternalPoints() {
    List<PartialPosition> points = Arrays.asList(new PartialPosition(0d, 0d, UnitUtils.Units.MM), new PartialPosition(0d, 10d, UnitUtils.Units.MM), new PartialPosition(10d, 10d, UnitUtils.Units.MM), new PartialPosition(5d, 5d, UnitUtils.Units.MM));
    List<PartialPosition> convexHull = MathUtils.generateConvexHull(points);
    assertEquals(3, convexHull.size());
    assertEquals(new PartialPosition(0d, 0d, UnitUtils.Units.MM), convexHull.get(0));
    assertEquals(new PartialPosition(10d, 10d, UnitUtils.Units.MM), convexHull.get(1));
    assertEquals(new PartialPosition(0d, 10d, UnitUtils.Units.MM), convexHull.get(2));
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Test(org.junit.Test)

Aggregations

PartialPosition (com.willwinder.universalgcodesender.model.PartialPosition)36 Test (org.junit.Test)19 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)10 List (java.util.List)8 InOrder (org.mockito.InOrder)8 Position (com.willwinder.universalgcodesender.model.Position)7 Collectors (java.util.stream.Collectors)6 CentralLookup (com.willwinder.ugs.nbp.lib.lookup.CentralLookup)4 GcodeParserException (com.willwinder.universalgcodesender.gcode.util.GcodeParserException)4 UGSEventListener (com.willwinder.universalgcodesender.listeners.UGSEventListener)4 BackendAPI (com.willwinder.universalgcodesender.model.BackendAPI)4 UGSEvent (com.willwinder.universalgcodesender.model.UGSEvent)4 UnitUtils (com.willwinder.universalgcodesender.model.UnitUtils)4 ControllerStateEvent (com.willwinder.universalgcodesender.model.events.ControllerStateEvent)4 FileStateEvent (com.willwinder.universalgcodesender.model.events.FileStateEvent)4 LoaderDialogHelper (com.willwinder.universalgcodesender.uielements.helpers.LoaderDialogHelper)4 com.willwinder.universalgcodesender.utils (com.willwinder.universalgcodesender.utils)4 GcodeViewParse (com.willwinder.universalgcodesender.visualizer.GcodeViewParse)4 LineSegment (com.willwinder.universalgcodesender.visualizer.LineSegment)4 VisualizerUtils (com.willwinder.universalgcodesender.visualizer.VisualizerUtils)4