Search in sources :

Example 1 with PartialPosition

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

the class SimplePath method toGcodePath.

@Override
public GcodePath toGcodePath() {
    Geometry geometry = ToolPathUtils.convertAreaToGeometry(new Area(source.getShape()), getGeometryFactory());
    Geometry bufferedGeometry = geometry.buffer(offset);
    List<Geometry> geometries = ToolPathUtils.toGeometryList(bufferedGeometry);
    ArrayList<List<PartialPosition>> coordinateList = new ArrayList<>();
    geometries.forEach(g -> {
        List<PartialPosition> geometryCoordinates = ToolPathUtils.geometryToCoordinates(g);
        double currentDepth = getStartDepth();
        while (currentDepth < getTargetDepth()) {
            currentDepth += getDepthPerPass();
            if (currentDepth > getTargetDepth()) {
                currentDepth = getTargetDepth();
            }
            final double depth = -currentDepth;
            coordinateList.add(geometryCoordinates.stream().map(numericCoordinate -> PartialPosition.builder().copy(numericCoordinate).setZ(depth).build()).collect(Collectors.toList()));
        }
    });
    return toGcodePath(coordinateList);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Area(java.awt.geom.Area) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with PartialPosition

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

the class AbstractToolPath method addSafeHeightSegmentTo.

protected void addSafeHeightSegmentTo(GcodePath gcodePath, PartialPosition coordinate) {
    addSafeHeightSegment(gcodePath);
    gcodePath.addSegment(SegmentType.MOVE, new PartialPosition(coordinate.getX(), coordinate.getY(), UnitUtils.Units.MM));
    gcodePath.addSegment(SegmentType.MOVE, PartialPosition.from(Axis.Z, 0d, UnitUtils.Units.MM));
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition)

Example 3 with PartialPosition

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

the class OutlineToolPath method toGcodePath.

@Override
public GcodePath toGcodePath() {
    List<Geometry> geometries;
    if (ToolPathUtils.isClosedGeometry(source.getShape())) {
        Geometry geometry = ToolPathUtils.convertAreaToGeometry(new Area(source.getShape()), getGeometryFactory());
        Geometry bufferedGeometry = geometry.buffer(offset);
        geometries = ToolPathUtils.toGeometryList(bufferedGeometry);
    } else {
        geometries = ToolPathUtils.convertShapeToGeometry(source.getShape(), getGeometryFactory());
    }
    ArrayList<List<PartialPosition>> coordinateList = new ArrayList<>();
    geometries.forEach(g -> {
        List<PartialPosition> geometryCoordinates = ToolPathUtils.geometryToCoordinates(g);
        double currentDepth = getStartDepth() - getDepthPerPass();
        while (currentDepth < getTargetDepth()) {
            currentDepth += getDepthPerPass();
            if (currentDepth > getTargetDepth()) {
                currentDepth = getTargetDepth();
            }
            final double depth = -currentDepth;
            coordinateList.add(geometryCoordinates.stream().map(numericCoordinate -> PartialPosition.builder().copy(numericCoordinate).setZ(depth).build()).collect(Collectors.toList()));
        }
    });
    return toGcodePath(coordinateList);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Area(java.awt.geom.Area) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with PartialPosition

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

the class OutlineAction method generateOutlineCommands.

public List<GcodeCommand> generateOutlineCommands(File gcodeFile) throws IOException, GcodeParserException {
    List<LineSegment> gcodeLineList = parseGcodeLinesFromFile(gcodeFile);
    // We only care about carving motion, filter those commands out
    List<PartialPosition> pointList = gcodeLineList.parallelStream().filter(lineSegment -> !lineSegment.isFastTraverse()).flatMap(lineSegment -> {
        // We map both the start and end points in MM
        PartialPosition start = PartialPosition.fromXY(lineSegment.getStart().getPositionIn(UnitUtils.Units.MM));
        PartialPosition end = PartialPosition.fromXY(lineSegment.getEnd().getPositionIn(UnitUtils.Units.MM));
        return Stream.of(start, end);
    }).distinct().collect(Collectors.toList());
    UnitUtils.Units preferredUnits = backend.getSettings().getPreferredUnits();
    double jogFeedRateInMM = backend.getSettings().getJogFeedRate() * UnitUtils.scaleUnits(preferredUnits, UnitUtils.Units.MM);
    List<PartialPosition> outline = MathUtils.generateConvexHull(pointList);
    return outline.stream().map(point -> new GcodeCommand(GcodeUtils.generateMoveToCommand(Code.G1.name(), point, jogFeedRateInMM))).collect(Collectors.toList());
}
Also used : UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) ActionID(org.openide.awt.ActionID) 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) ImageUtilities(org.openide.util.ImageUtilities) GcodeUtils(com.willwinder.universalgcodesender.gcode.util.GcodeUtils) UGSEvent(com.willwinder.universalgcodesender.model.UGSEvent) UGSEventListener(com.willwinder.universalgcodesender.listeners.UGSEventListener) GcodeViewParse(com.willwinder.universalgcodesender.visualizer.GcodeViewParse) GcodeParserException(com.willwinder.universalgcodesender.gcode.util.GcodeParserException) CentralLookup(com.willwinder.ugs.nbp.lib.lookup.CentralLookup) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Code(com.willwinder.universalgcodesender.gcode.util.Code) VisualizerUtils(com.willwinder.universalgcodesender.visualizer.VisualizerUtils) IOException(java.io.IOException) Logger(java.util.logging.Logger) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) 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) java.awt(java.awt) ActionReferences(org.openide.awt.ActionReferences) List(java.util.List) Stream(java.util.stream.Stream) ControllerState(com.willwinder.universalgcodesender.listeners.ControllerState) ActionRegistration(org.openide.awt.ActionRegistration) LineSegment(com.willwinder.universalgcodesender.visualizer.LineSegment) javax.swing(javax.swing) UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) LineSegment(com.willwinder.universalgcodesender.visualizer.LineSegment)

Example 5 with PartialPosition

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

the class GrblControllerTest method testJogMachineTo.

/**
 * Test of jogMachineTo method
 */
@Test
public void testJogMachineTo() throws Exception {
    System.out.println("jogMachineTo");
    GrblController instance = new GrblController(mgc);
    instance.setDistanceModeCode("G90");
    instance.setUnitsCode("G21");
    instance.openCommPort(getSettings().getConnectionDriver(), "foo", 2400);
    // Abstract controller should be used when grbl jog mode is disabled.
    instance.rawResponseHandler("Grbl 0.8c");
    instance.jogMachineTo(new PartialPosition(1.0, 2.0, 3.0, UnitUtils.Units.MM), 200);
    assertEquals("G21G90G1X1Y2Z3F200", mgc.queuedStrings.get(2));
    assertEquals("G90 G21 ", mgc.queuedStrings.get(3));
    instance.jogMachineTo(new PartialPosition(1.0, 2.0, UnitUtils.Units.MM), 200);
    assertEquals("G21G90G1X1Y2F200", mgc.queuedStrings.get(4));
    assertEquals("G90 G21 ", mgc.queuedStrings.get(5));
    instance.jogMachineTo(new PartialPosition(1.2345678, 2.0, UnitUtils.Units.MM), 200);
    assertEquals("G21G90G1X1.235Y2F200", mgc.queuedStrings.get(6));
    assertEquals("G90 G21 ", mgc.queuedStrings.get(7));
    instance.jogMachineTo(new PartialPosition(1.0, 2.0, UnitUtils.Units.INCH), 200);
    assertEquals("G20G90G1X1Y2F200", mgc.queuedStrings.get(8));
    assertEquals("G90 G21 ", mgc.queuedStrings.get(9));
}
Also used : PartialPosition(com.willwinder.universalgcodesender.model.PartialPosition)

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