feat(marathon): display path-finding on gui

This commit is contained in:
Paul Alnet 2024-05-26 11:19:02 +02:00
parent d6f469e32f
commit 0dbe233d75
5 changed files with 37 additions and 1 deletions

View file

@ -62,6 +62,8 @@ public class MarathonAlgorithm extends ShortestPathAlgorithm {
if (newPath != null) {
// Ajout du path trouvé à l'indice on l'a enlevé
path.replaceArc(arcToRemove, newPath.getArcs());
// display path
notifyMarathonPathUpdated(path, newPath);
}
}

View file

@ -2,6 +2,7 @@ package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.algorithm.AbstractAlgorithm;
import org.insa.graphs.model.Node;
import org.insa.graphs.model.Path;
public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPathObserver> {
@ -69,6 +70,17 @@ public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPa
}
}
/**
* Notify the observer that the path has been updated.
*
* @param path Path that has been updated.
*/
public void notifyMarathonPathUpdated(Path path, Path newSegment) {
for (ShortestPathObserver obs: getObservers()) {
obs.notifyMarathonPathUpdated(path, newSegment);
}
}
public double getCostPath() {
return this.pathCost;
}

View file

@ -1,6 +1,7 @@
package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.model.Node;
import org.insa.graphs.model.Path;
public interface ShortestPathObserver {
@ -34,4 +35,11 @@ public interface ShortestPathObserver {
*/
public void notifyDestinationReached(Node node);
/**
* Notify the observer that the path has been updated.
*
* @param path Path that has been updated.
*/
public void notifyMarathonPathUpdated(Path path, Path newSegment);
}

View file

@ -3,6 +3,7 @@ package org.insa.graphs.algorithm.shortestpath;
import java.io.PrintStream;
import org.insa.graphs.model.Node;
import org.insa.graphs.model.Path;
public class ShortestPathTextObserver implements ShortestPathObserver {
@ -34,4 +35,9 @@ public class ShortestPathTextObserver implements ShortestPathObserver {
}
@Override
public void notifyMarathonPathUpdated(Path path, Path newSegment) {
// noop
}
}

View file

@ -6,6 +6,7 @@ import org.insa.graphs.algorithm.shortestpath.ShortestPathObserver;
import org.insa.graphs.gui.drawing.Drawing;
import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
import org.insa.graphs.model.Node;
import org.insa.graphs.model.Path;
public class ShortestPathGraphicObserver implements ShortestPathObserver {
@ -39,4 +40,11 @@ public class ShortestPathGraphicObserver implements ShortestPathObserver {
// drawing.drawMarker(node.getPoint(), Color.RED);
}
@Override
public void notifyMarathonPathUpdated(Path path, Path newSegment) {
drawing.clearOverlays();
drawing.drawPath(path, Color.BLUE, true);
drawing.drawPath(newSegment, Color.RED, false);
}
}