Skip to content

Commit 0ad8a63

Browse files
committed
Cleaned up service code in Document Actions
1 parent 2c48c0b commit 0ad8a63

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

app/src/main/java/org/team2363/helixnavigator/document/DocumentActions.java

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
import com.jlbabilino.json.JSONSerializerException;
3636

3737
import javafx.beans.property.BooleanProperty;
38-
import javafx.beans.property.ObjectProperty;
3938
import javafx.beans.property.ReadOnlyBooleanProperty;
4039
import javafx.beans.property.SimpleBooleanProperty;
41-
import javafx.beans.property.SimpleObjectProperty;
4240
import javafx.beans.value.ObservableValue;
4341
import javafx.concurrent.Service;
4442
import javafx.concurrent.Task;
@@ -397,8 +395,6 @@ public void paste() {
397395

398396
private static class TrajectoryGenerationService extends Service<HolonomicTrajectory> {
399397

400-
// private final ObjectProperty<SwerveDrivetrain> drive = new SimpleObjectProperty<>(this, "drive", null);
401-
// private final ObjectProperty<HolonomicPath> path = new SimpleObjectProperty<>(this, "path", null);
402398
private SwerveDrivetrain drive = null;
403399
private HolonomicPath path = null;
404400

@@ -410,28 +406,24 @@ protected Task<HolonomicTrajectory> createTask() {
410406
Task<HolonomicTrajectory> optimizeTask = new Task<HolonomicTrajectory>() {
411407
@Override
412408
protected HolonomicTrajectory call() throws PluginLoadException, InvalidPathException, TrajectoryGenerationException {
413-
// Thread generationThread = Thread.currentThread();
414409
System.out.println("Path optimizing: " + path.toString());
415410
if (drive != null && path != null) {
416-
// new Thread(() -> {
417-
// while (!isCancelled()) {}
418-
// generationThread.stop();
419-
// }).start();
420411
HolonomicTrajectory traj = OptimalTrajectoryGenerator.generate(drive, path);
421412
System.out.println("Generation complete, closing task...");
422413
return traj;
423414
} else {
424415
throw new TrajectoryGenerationException("No path specified for optimization service.");
425416
}
426-
// System.out.println("Error generating path: " + e.getMessage() + System.lineSeparator());
427417
}
428418
};
429419
return optimizeTask;
430420
}
431421
}
432422

433-
private static final TrajectoryGenerationService SERVICE = new TrajectoryGenerationService();
434-
public static final ReadOnlyBooleanProperty IS_GENERATION_RUNNING = SERVICE.runningProperty();
423+
private final TrajectoryGenerationService service = new TrajectoryGenerationService();
424+
public final ReadOnlyBooleanProperty generationRunningProperty() {
425+
return service.runningProperty();
426+
}
435427
public void generateTrajectory() {
436428
if (documentManager.getIsDocumentOpen() && documentManager.getDocument().isPathSelected()) {
437429
HDocument hDocument = documentManager.getDocument();
@@ -442,31 +434,17 @@ public void generateTrajectory() {
442434
obstacles.add(hPath.getObstacles().get(i).toObstacle());
443435
}
444436
HolonomicPath path = hPath.toPath(obstacles);
445-
SERVICE.drive = drive;
446-
SERVICE.path = path;
447-
SERVICE.setOnSucceeded(workerState -> {
437+
service.drive = drive;
438+
service.path = path;
439+
service.setOnSucceeded(workerState -> {
448440
HolonomicTrajectory traj = (HolonomicTrajectory) workerState.getSource().getValue();
449441
hPath.setTrajectory(HTrajectory.fromTrajectory(traj));
450442
});
451-
if (!SERVICE.isRunning()) {
452-
SERVICE.restart();
443+
if (!service.isRunning()) {
444+
service.restart();
453445
}
454446
}
455447
}
456-
// public void toggleTrajectoryGeneration() {
457-
// if (SERVICE.isRunning()) {
458-
// System.out.println("Cancelling trajopt");
459-
// SERVICE.cancel();
460-
// } else {
461-
// System.out.println("Restarting trajopt");
462-
// generateTrajectory();
463-
// }
464-
// }
465-
// public void cancelTrajectoryGeneration() {
466-
// if (SERVICE.isRunning()) {
467-
// SERVICE.cancel();
468-
// }
469-
// }
470448

471449
private static final Rotate ROTATE_90_CLOCKWISE = new Rotate(-90);
472450
private static final Rotate ROTATE_90_COUNTERCLOCKWISE = new Rotate(90);

0 commit comments

Comments
 (0)