Search in sources :

Example 31 with PartialPosition

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

the class MathUtilsTest method orientationWithPointsInClockwiseOrder.

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

Example 32 with PartialPosition

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

the class TranslateToZeroAction method getLowerLeftCorner.

private Position getLowerLeftCorner(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.getLowerLeftCorner(pointList);
}
Also used : ActionID(org.openide.awt.ActionID) 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) ActionReference(org.openide.awt.ActionReference) UGSEvent(com.willwinder.universalgcodesender.model.UGSEvent) UGSEventListener(com.willwinder.universalgcodesender.listeners.UGSEventListener) EditorActionRegistration(org.netbeans.api.editor.EditorActionRegistration) Level(java.util.logging.Level) GcodeViewParse(com.willwinder.universalgcodesender.visualizer.GcodeViewParse) GcodeLanguageConfig(com.willwinder.ugs.nbp.editor.GcodeLanguageConfig) HelpCtx(org.openide.util.HelpCtx) 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) TranslateProcessor(com.willwinder.universalgcodesender.gcode.processors.TranslateProcessor) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) GcodeDataObject(com.willwinder.ugs.nbp.editor.GcodeDataObject) LocalizingService(com.willwinder.ugs.nbp.lib.services.LocalizingService) 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) ActionReferences(org.openide.awt.ActionReferences) List(java.util.List) Stream(java.util.stream.Stream) ActionRegistration(org.openide.awt.ActionRegistration) LineSegment(com.willwinder.universalgcodesender.visualizer.LineSegment) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) LineSegment(com.willwinder.universalgcodesender.visualizer.LineSegment)

Example 33 with PartialPosition

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

the class AbstractToolPath method addSafeHeightSegment.

protected void addSafeHeightSegment(GcodePath gcodePath) {
    PartialPosition safeHeightCoordinate = PartialPosition.from(Axis.Z, getSafeHeight(), UnitUtils.Units.MM);
    gcodePath.addSegment(SegmentType.MOVE, safeHeightCoordinate);
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition)

Example 34 with PartialPosition

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

the class DrillCenterToolPath method toGcodePath.

@Override
public GcodePath toGcodePath() {
    Point2D center = source.getCenter();
    PartialPosition centerPosition = PartialPosition.builder().setX(center.getX()).setY(center.getY()).setUnits(UnitUtils.Units.MM).build();
    GcodePath gcodePath = new GcodePath();
    addSafeHeightSegmentTo(gcodePath, centerPosition);
    double currentDepth = getStartDepth() - getDepthPerPass();
    while (currentDepth < getTargetDepth()) {
        currentDepth += getDepthPerPass();
        if (currentDepth > getTargetDepth()) {
            currentDepth = getTargetDepth();
        }
        final double depth = -currentDepth;
        gcodePath.addSegment(SegmentType.POINT, PartialPosition.builder().copy(centerPosition).setZ(depth).build());
        gcodePath.addSegment(SegmentType.POINT, PartialPosition.builder().copy(centerPosition).setZ(0d).build());
    }
    addSafeHeightSegment(gcodePath);
    return gcodePath;
}
Also used : Point2D(java.awt.geom.Point2D) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) GcodePath(com.willwinder.ugs.nbp.designer.io.gcode.path.GcodePath)

Example 35 with PartialPosition

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

the class PocketToolPathTest method pocketShouldNotExceedTheGeometry.

@Test
public void pocketShouldNotExceedTheGeometry() {
    double toolRadius = 2.5;
    double geometrySize = 10d;
    double safeHeight = 1;
    double targetDepth = -10;
    int depthPerPass = 1;
    Rectangle rectangle = new Rectangle();
    rectangle.setSize(new Size(geometrySize, geometrySize));
    PocketToolPath simplePocket = new PocketToolPath(rectangle);
    simplePocket.setTargetDepth(targetDepth);
    simplePocket.setDepthPerPass(depthPerPass);
    simplePocket.setToolDiameter(toolRadius * 2);
    simplePocket.setStepOver(1);
    simplePocket.setSafeHeight(safeHeight);
    List<Segment> segmentList = simplePocket.toGcodePath().getSegments();
    Segment firstSegment = segmentList.get(0);
    assertEquals("The first segment should move to safe height", safeHeight, firstSegment.point.getAxis(Axis.Z), 0.1);
    assertFalse("The first segment should not move X", firstSegment.point.hasAxis(Axis.X));
    assertFalse("The first segment should not move Y", firstSegment.point.hasAxis(Axis.Y));
    Segment secondSegment = segmentList.get(1);
    assertEquals("The second segment should move to safe height", safeHeight, firstSegment.point.getAxis(Axis.Z), 0.1);
    assertEquals("The second segment should move to first X position", safeHeight, secondSegment.point.getAxis(Axis.X), toolRadius);
    assertEquals("The second segment should move to first Y position", safeHeight, secondSegment.point.getAxis(Axis.Y), toolRadius);
    // Make sure that we don't move outside the boundary of the geometry
    segmentList.stream().filter(segment -> segment.type == SegmentType.LINE || segment.type == SegmentType.POINT).forEach(segment -> {
        assertTrue("Point was outside boundary of 10x10 shape: X=" + segment.getPoint().getAxis(Axis.X), segment.getPoint().getAxis(Axis.X) >= toolRadius);
        assertTrue("Point was outside boundary of 10x10 shape: Y=" + segment.getPoint().getAxis(Axis.Y), segment.getPoint().getAxis(Axis.Y) >= toolRadius);
        assertTrue("Point was outside boundary of 10x10 shape: X=" + segment.getPoint().getAxis(Axis.X), segment.getPoint().getAxis(Axis.X) <= geometrySize - toolRadius);
        assertTrue("Point was outside boundary of 10x10 shape: Y=" + segment.getPoint().getAxis(Axis.Y), segment.getPoint().getAxis(Axis.Y) <= geometrySize - toolRadius);
        assertTrue("Point was outside boundary of 10x10 shape: Z=" + segment.getPoint().getAxis(Axis.Z), segment.getPoint().getAxis(Axis.Z) <= 0);
        assertTrue("Point was outside boundary of 10x10 shape: Z=" + segment.getPoint().getAxis(Axis.Z), segment.getPoint().getAxis(Axis.Z) >= targetDepth);
    });
    List<Segment> drillOperations = segmentList.stream().filter(segment -> segment.type == SegmentType.POINT).collect(Collectors.toList());
    assertEquals("There should be a number of drill operations when making a pocket", Math.abs((targetDepth - depthPerPass) / depthPerPass), drillOperations.size(), 0.1);
    PartialPosition point = drillOperations.get(drillOperations.size() - 1).getPoint();
    assertEquals("Last operation should reach the target depth", targetDepth, point.getAxis(Axis.Z), 0.1);
}
Also used : Size(com.willwinder.ugs.nbp.designer.model.Size) Segment(com.willwinder.ugs.nbp.designer.io.gcode.path.Segment) Axis(com.willwinder.universalgcodesender.model.Axis) List(java.util.List) Rectangle(com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle) SegmentType(com.willwinder.ugs.nbp.designer.io.gcode.path.SegmentType) Test(org.junit.Test) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) Size(com.willwinder.ugs.nbp.designer.model.Size) Rectangle(com.willwinder.ugs.nbp.designer.entities.cuttable.Rectangle) Segment(com.willwinder.ugs.nbp.designer.io.gcode.path.Segment) 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