/* * Author: Cedric Holzl - Mohamed Khadri * Sciper: 257844 - 261203 */ package ch.epfl.alpano.gui; import java.beans.Beans; import java.util.ArrayList; import java.util.List; import javafx.beans.property.ObjectProperty; import javafx.beans.property.ReadOnlyObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Node; import javafx.scene.image.Image; import ch.epfl.alpano.Panorama; import ch.epfl.alpano.PanoramaComputer; import ch.epfl.alpano.dem.ContinuousElevationModel; import ch.epfl.alpano.mapzen.MapzenManager; import ch.epfl.alpano.summit.Summit; import static ch.epfl.alpano.gui.PanoramaRenderer.renderPanorama; import static javafx.application.Platform.runLater; /** * Class used to link the panorama computing with the Graphical interface (through the PanoramaParametersBean) */ public class PanoramaComputerBean extends Beans { private final ObjectProperty panoramaProperty; private final ObjectProperty parametersProperty; private final ObjectProperty imageProperty; private final ObjectProperty> labelsProperty; private final ObjectProperty cDEM; private final ObjectProperty imp; private final ObjectProperty downloadProperty; private final ObjectProperty downloadTextProperty; private final List summits; private final MapzenManager HGTGetter = new MapzenManager(); /** * Constructs a bean for a panoramaComputer * @param summits : a list of summits */ public PanoramaComputerBean(List summits){ this.cDEM = new SimpleObjectProperty(); this.cDEM.bind(HGTGetter.cDEM()); this.downloadProperty = new SimpleObjectProperty(false); this.summits = summits; this.parametersProperty = new SimpleObjectProperty(null); ObservableList oList = FXCollections.observableList(new ArrayList()); this.labelsProperty = new SimpleObjectProperty>(oList); this.panoramaProperty = new SimpleObjectProperty(null); this.imageProperty = new SimpleObjectProperty(null); this.imp = new SimpleObjectProperty(CustomPainters.GRADDEMPOST); HGTGetter.cDEM().addListener( (b, o, n) -> runLater(this::updatePanorama)); this.downloadTextProperty = new SimpleObjectProperty(); HGTGetter.text().addListener( (b, o, n) -> runLater(this::updateDownloadText)); this.imp.addListener( (b, o, n) -> runLater(this::repaintPanorama)); parametersProperty.addListener((b, o, n) -> this.downloadHGT()); } /** * Returns the elevation model property object * @return ContinuousElevationModel property object */ ReadOnlyObjectProperty cDem(){ return this.cDEM; } /** * Returns the panorama property object * @return panorama property object */ ReadOnlyObjectProperty panoramaProperty(){ return panoramaProperty; } /** * Returns the parameters property object * @return parameters property object */ ObjectProperty parametersProperty(){ return parametersProperty; } /** * Returns the image property object * @return image property object */ ReadOnlyObjectProperty imageProperty(){ return imageProperty; } /** * Returns the labels property object * @return labels property object */ ReadOnlyObjectProperty> labelsProperty(){ return labelsProperty; } /** * Returns the painter property object * @return Custom Painter property object */ ReadOnlyObjectProperty painterProperty() { return imp; } /** * Returns the download property object * This object is used to set if Mapzen is currently downloading * @return boolean download property object */ ReadOnlyObjectProperty downloadProperty(){ return downloadProperty; } /** * Returns the labels * @return labels */ ObservableList getLabels(){ return labelsProperty.get(); } /** * Returns the panorama * @return panorama */ Panorama getPanorama(){ return panoramaProperty.get(); } /** * Returns the parameters * @return parameters */ PanoramaUserParameters getParameters(){ return parametersProperty.get(); } /** * Updates the parameters * @param newParameters : new PanoramaUserParameters */ void setParameters(PanoramaUserParameters newParameters){ this.parametersProperty.set(newParameters); } /** * Updates the custom painter * @param cp : new painter */ void setPainter(CustomPainters cp) { imp.set(cp); } /** * Retuns the image * @return image */ Image getImage(){ return imageProperty.get(); } /** * Text displayed when downloading property object * @return download text property object */ ReadOnlyObjectProperty downloadTextProperty(){ return downloadTextProperty; } /** * Updates the download text getting new text from the MapzenManager */ private void updateDownloadText(){ this.downloadTextProperty.set(HGTGetter.text().get()); } /** * Downloads the HGT Files */ private void downloadHGT(){ this.downloadProperty.set(true); HGTGetter.update(this.getParameters().panoramaDisplayParameters()); } /** * Repaints the panorama */ private void repaintPanorama(){ if(this.getPanorama()!=null) this.imageProperty.set(renderPanorama(this.getPanorama(), imp.get().painter(this.getPanorama()))); } /** * Computes the new panorama */ private void updatePanorama() { this.downloadProperty.set(false); Panorama panorama = new PanoramaComputer(cDEM.get()).computePanorama(this.getParameters().panoramaComputeParameters()); List newLabels = new Labelizer(cDEM.get(), summits).labels(this.getParameters().panoramaDisplayParameters()); this.panoramaProperty.set(panorama); this.imageProperty.set(renderPanorama(panorama, imp.get().painter(panorama))); this.labelsProperty().get().setAll(newLabels); } }