Search in sources :

Example 1 with Waypoint

use of edu.wpi.first.pathweaver.Waypoint in project PathWeaver by wpilibsuite.

the class DragHandler method handlePathMoveDrag.

private void handlePathMoveDrag(DragEvent event, Path path, Waypoint point) {
    double offsetX = event.getX() - point.getX();
    double offsetY = event.getY() + point.getY();
    // Make sure all waypoints will be within the bounds
    for (Waypoint checkPoint : path.getWaypoints()) {
        double wpNewX = checkPoint.getX() + offsetX;
        double wpNewY = -checkPoint.getY() + offsetY;
        if (!controller.checkBounds(wpNewX, -wpNewY)) {
            return;
        }
    }
    // Apply new positions
    for (Waypoint changedPoint : path.getWaypoints()) {
        double wpNewX = changedPoint.getX() + offsetX;
        double wpNewY = changedPoint.getY() - offsetY;
        changedPoint.setX(wpNewX);
        changedPoint.setY(wpNewY);
    }
    path.update();
}
Also used : Waypoint(edu.wpi.first.pathweaver.Waypoint)

Example 2 with Waypoint

use of edu.wpi.first.pathweaver.Waypoint in project PathWeaver by wpilibsuite.

the class Path method recalculateTangents.

/**
 * Recalculate the tangents for the waypoint provided, as well as those before and after it.
 * This implementation skips over non-existent waypoints, calling the {@link #updateTangent(Waypoint)} on the others.
 * @param wp the waypoint to recalculate tangents for
 */
public void recalculateTangents(Waypoint wp) {
    int curWpIndex = getWaypoints().indexOf(wp);
    if (curWpIndex - 1 > 0) {
        Waypoint previous = getWaypoints().get(curWpIndex - 1);
        updateTangent(previous);
    }
    updateTangent(wp);
    if (curWpIndex + 1 < waypoints.size()) {
        Waypoint next = getWaypoints().get(curWpIndex + 1);
        updateTangent(next);
    }
}
Also used : Waypoint(edu.wpi.first.pathweaver.Waypoint) Waypoint(edu.wpi.first.pathweaver.Waypoint)

Example 3 with Waypoint

use of edu.wpi.first.pathweaver.Waypoint in project PathWeaver by wpilibsuite.

the class Path method flip.

/**
 * Reflects the Path across an axis.
 * The coordinate system's origin is the starting point of the Path.
 *
 * @param horizontal Flip over horizontal axis?
 * @param drawPane   Pane to check validity of new points.
 */
public void flip(boolean horizontal, Pane drawPane) {
    // Check if any new points are outside drawPane
    for (Waypoint wp : waypoints) {
        if (!drawPane.contains(reflectPoint(getStart(), wp, horizontal, false))) {
            Alert a = new Alert(Alert.AlertType.INFORMATION);
            FxUtils.applyDarkMode(a);
            a.setTitle("");
            a.setHeaderText("The path could not be flipped.");
            a.setContentText("Flipping this path would cause it to go out of bounds");
            a.showAndWait();
            // The new path is invalid
            return;
        }
    }
    // New waypoints are valid, update all Waypoints
    for (Waypoint wp : waypoints) {
        Point2D reflectedPos = reflectPoint(getStart(), wp, horizontal, false);
        Point2D reflectedTangent = reflectPoint(getStart(), wp, horizontal, true);
        wp.setX(reflectedPos.getX());
        wp.setY(reflectedPos.getY());
        wp.setTangent(reflectedTangent);
    }
}
Also used : Point2D(javafx.geometry.Point2D) Waypoint(edu.wpi.first.pathweaver.Waypoint) Alert(javafx.scene.control.Alert)

Example 4 with Waypoint

use of edu.wpi.first.pathweaver.Waypoint in project PathWeaver by wpilibsuite.

the class Path method enableSubchildSelector.

public void enableSubchildSelector(int i) {
    this.subchildIdx = i;
    for (Waypoint wp : waypoints) {
        wp.enableSubchildSelector(subchildIdx);
    }
    spline.enableSubchildSelector(subchildIdx);
}
Also used : Waypoint(edu.wpi.first.pathweaver.Waypoint)

Example 5 with Waypoint

use of edu.wpi.first.pathweaver.Waypoint in project PathWeaver by wpilibsuite.

the class Path method deselectWaypoint.

/**
 * Selects the given waypoint by calling the appropriate methods in {@link CurrentSelections}, making care to update the waypoint.
 * This implementation does not currently null out {@link CurrentSelections#curPathProperty()} due to a NPE.
 * @param waypoint the waypoint to deselect
 */
public void deselectWaypoint(Waypoint waypoint) {
    Waypoint curWaypoint = CurrentSelections.getCurWaypoint();
    if (CurrentSelections.getCurWaypoint() == waypoint) {
        curWaypoint.getIcon().pseudoClassStateChanged(SELECTED_CLASS, false);
        mainGroup.requestFocus();
        CurrentSelections.setCurWaypoint(null);
    }
}
Also used : Waypoint(edu.wpi.first.pathweaver.Waypoint)

Aggregations

Waypoint (edu.wpi.first.pathweaver.Waypoint)12 QuinticHermiteSpline (edu.wpi.first.math.spline.QuinticHermiteSpline)3 Point2D (javafx.geometry.Point2D)3 PoseWithCurvature (edu.wpi.first.math.spline.PoseWithCurvature)1 Spline (edu.wpi.first.math.spline.Spline)1 ProjectPreferences (edu.wpi.first.pathweaver.ProjectPreferences)1 Path (edu.wpi.first.pathweaver.path.Path)1 AbstractSpline (edu.wpi.first.pathweaver.spline.AbstractSpline)1 SplineSegment (edu.wpi.first.pathweaver.spline.SplineSegment)1 Alert (javafx.scene.control.Alert)1 Dragboard (javafx.scene.input.Dragboard)1 UnitConverter (javax.measure.UnitConverter)1