Overload hotkey to allow toggling between MapWithAI layer and OsmData layer

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2019-10-30 10:54:51 -06:00
rodzic 2520e1b0ea
commit 75565272fa
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
6 zmienionych plików z 57 dodań i 24 usunięć

Wyświetl plik

@ -27,6 +27,10 @@
<property name="ivy.jar.dir" value="${ivy.home}/lib"/> <property name="ivy.jar.dir" value="${ivy.home}/lib"/>
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/> <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/>
<fileset id="plugin.requires.jars" dir="${plugin.dist.dir}">
<include name="utilsplugin2.jar"/>
</fileset>
<target name="download-ivy"> <target name="download-ivy">
<mkdir dir="${ivy.jar.dir}"/> <mkdir dir="${ivy.jar.dir}"/>
<get src="https://jcenter.bintray.com/org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar" dest="${ivy.jar.file}" usetimestamp="true" ignoreerrors="true"/> <get src="https://jcenter.bintray.com/org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar" dest="${ivy.jar.file}" usetimestamp="true" ignoreerrors="true"/>

Wyświetl plik

@ -20,6 +20,7 @@ import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.osm.DataSet; import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.Notification; import org.openstreetmap.josm.gui.Notification;
import org.openstreetmap.josm.gui.layer.Layer;
import org.openstreetmap.josm.gui.layer.OsmDataLayer; import org.openstreetmap.josm.gui.layer.OsmDataLayer;
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin; import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
import org.openstreetmap.josm.tools.Shortcut; import org.openstreetmap.josm.tools.Shortcut;
@ -39,8 +40,26 @@ public class MapWithAIAction extends JosmAction {
@Override @Override
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
if (isEnabled()) { if (isEnabled()) {
MapWithAIDataUtils.getMapWithAIData(MapWithAIDataUtils.getLayer(true)); final boolean hasLayer = MapWithAIDataUtils.getLayer(false) != null;
if (MapWithAIDataUtils.getMapWithAIData(MapWithAIDataUtils.getLayer(true))) {
createMessageDialog(); createMessageDialog();
} else if (hasLayer) {
toggleLayer();
}
}
}
private static void toggleLayer() {
final OsmDataLayer mapwithai = MapWithAIDataUtils.getLayer(false);
final OsmDataLayer osmData = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream()
.filter(layer -> !(layer instanceof MapWithAILayer)).findFirst().orElse(null);
final Layer currentLayer = MainApplication.getLayerManager().getActiveLayer();
if (currentLayer != null) {
if (currentLayer.equals(mapwithai) && osmData != null) {
MainApplication.getLayerManager().setActiveLayer(osmData);
} else if (currentLayer.equals(osmData) && mapwithai != null) {
MainApplication.getLayerManager().setActiveLayer(mapwithai);
}
} }
} }

Wyświetl plik

@ -182,25 +182,31 @@ public final class MapWithAIDataUtils {
* Get data for a {@link MapWithAILayer} * Get data for a {@link MapWithAILayer}
* *
* @param layer The {@link MapWithAILayer} to add data to * @param layer The {@link MapWithAILayer} to add data to
* @return true if data was downloaded
*/ */
public static void getMapWithAIData(MapWithAILayer layer) { public static boolean getMapWithAIData(MapWithAILayer layer) {
final List<OsmDataLayer> osmLayers = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class) final List<OsmDataLayer> osmLayers = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class)
.stream().filter(obj -> !MapWithAILayer.class.isInstance(obj)).collect(Collectors.toList()); .stream().filter(obj -> !MapWithAILayer.class.isInstance(obj)).collect(Collectors.toList());
boolean gotData = false;
for (final OsmDataLayer osmLayer : osmLayers) { for (final OsmDataLayer osmLayer : osmLayers) {
if (!osmLayer.isLocked()) { if (!osmLayer.isLocked()) {
getMapWithAIData(layer, osmLayer); if (getMapWithAIData(layer, osmLayer)) {
gotData = true;
} }
} }
} }
return gotData;
}
/** /**
* Get the data for MapWithAI * Get the data for MapWithAI
* *
* @param layer A pre-existing {@link MapWithAILayer} * @param layer A pre-existing {@link MapWithAILayer}
* @param osmLayer The osm datalayer with a set of bounds * @param osmLayer The osm datalayer with a set of bounds
* @return true if data was downloaded
*/ */
public static void getMapWithAIData(MapWithAILayer layer, OsmDataLayer osmLayer) { public static boolean getMapWithAIData(MapWithAILayer layer, OsmDataLayer osmLayer) {
getMapWithAIData(layer, return getMapWithAIData(layer,
osmLayer.getDataSet().getDataSourceBounds().stream().map(Bounds::toBBox).collect(Collectors.toList())); osmLayer.getDataSet().getDataSourceBounds().stream().map(Bounds::toBBox).collect(Collectors.toList()));
} }
@ -209,9 +215,10 @@ public final class MapWithAIDataUtils {
* *
* @param layer A pre-existing {@link MapWithAILayer} * @param layer A pre-existing {@link MapWithAILayer}
* @param bboxes The bboxes to get the data in * @param bboxes The bboxes to get the data in
* @return true if data was downloaded
*/ */
public static void getMapWithAIData(MapWithAILayer layer, BBox... bboxes) { public static boolean getMapWithAIData(MapWithAILayer layer, BBox... bboxes) {
getMapWithAIData(layer, Arrays.asList(bboxes)); return getMapWithAIData(layer, Arrays.asList(bboxes));
} }
/** /**
@ -219,8 +226,9 @@ public final class MapWithAIDataUtils {
* *
* @param layer A pre-existing {@link MapWithAILayer} * @param layer A pre-existing {@link MapWithAILayer}
* @param bboxes The bboxes to get the data in * @param bboxes The bboxes to get the data in
* @return true if data was downloaded
*/ */
public static void getMapWithAIData(MapWithAILayer layer, Collection<BBox> bboxes) { public static boolean getMapWithAIData(MapWithAILayer layer, Collection<BBox> bboxes) {
final DataSet mapWithAISet = layer.getDataSet(); final DataSet mapWithAISet = layer.getDataSet();
final List<BBox> mapWithAIBounds = mapWithAISet.getDataSourceBounds().stream().map(Bounds::toBBox) final List<BBox> mapWithAIBounds = mapWithAISet.getDataSourceBounds().stream().map(Bounds::toBBox)
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -228,6 +236,7 @@ public final class MapWithAIDataUtils {
.filter(bbox -> mapWithAIBounds.stream().noneMatch(tBBox -> tBBox.bounds(bbox))) .filter(bbox -> mapWithAIBounds.stream().noneMatch(tBBox -> tBBox.bounds(bbox)))
.collect(Collectors.toList()); .collect(Collectors.toList());
final List<BBox> toDownload = reduceBBox(mapWithAIBounds, editSetBBoxes); final List<BBox> toDownload = reduceBBox(mapWithAIBounds, editSetBBoxes);
if (!toDownload.isEmpty()) {
getForkJoinPool().execute(() -> { getForkJoinPool().execute(() -> {
final DataSet newData = getData(toDownload); final DataSet newData = getData(toDownload);
final Lock lock = layer.getLock(); final Lock lock = layer.getLock();
@ -239,6 +248,8 @@ public final class MapWithAIDataUtils {
} }
}); });
} }
return !toDownload.isEmpty();
}
private static List<BBox> reduceBBox(List<BBox> alreadyDownloaded, List<BBox> wantToDownload) { private static List<BBox> reduceBBox(List<BBox> alreadyDownloaded, List<BBox> wantToDownload) {
final List<BBox> alreadyDownloadedReduced = new ArrayList<>(alreadyDownloaded); final List<BBox> alreadyDownloadedReduced = new ArrayList<>(alreadyDownloaded);

Wyświetl plik

@ -197,7 +197,7 @@ public final class MapWithAIPreferenceHelper {
} }
/** /**
* @return A map of tags to replacement tags (use {@link Tag.ofString} to parse) * @return A map of tags to replacement tags (use {@link Tag#ofString} to parse)
*/ */
public static Map<String, String> getReplacementTags() { public static Map<String, String> getReplacementTags() {
final Map<String, String> defaultMap = Collections.emptyMap(); final Map<String, String> defaultMap = Collections.emptyMap();

Wyświetl plik

@ -41,7 +41,6 @@ public class OsmReaderCustom extends OsmReader {
* @param source the source input stream. Must not be null. * @param source the source input stream. Must not be null.
* @param progressMonitor the progress monitor. If null, {@link NullProgressMonitor#INSTANCE} is assumed * @param progressMonitor the progress monitor. If null, {@link NullProgressMonitor#INSTANCE} is assumed
* @param convertUnknownToTags true if unknown xml attributes should be kept as tags * @param convertUnknownToTags true if unknown xml attributes should be kept as tags
* @param saveOriginalId if true, keep the original id (as a tag, "current_id")
* *
* @return the dataset with the parsed data * @return the dataset with the parsed data
* @throws IllegalDataException if an error was found while parsing the data from the source * @throws IllegalDataException if an error was found while parsing the data from the source

Wyświetl plik

@ -118,7 +118,7 @@ public class MergeDuplicateWays extends Command {
* Check for ways that are (partial) duplicates, and if so merge them * Check for ways that are (partial) duplicates, and if so merge them
* *
* @param way A way to check * @param way A way to check
* @return non-null command if there are duplicate ways * @param commands A list of commands to add to
*/ */
public static void checkForDuplicateWays(Way way, List<Command> commands) { public static void checkForDuplicateWays(Way way, List<Command> commands) {
final Collection<Way> nearbyWays = way.getDataSet().searchWays(way.getBBox()); final Collection<Way> nearbyWays = way.getDataSet().searchWays(way.getBBox());
@ -294,7 +294,7 @@ public class MergeDuplicateWays extends Command {
* *
* @param way1 An initial way with nodes * @param way1 An initial way with nodes
* @param way2 A way that may have duplicate nodes with way1 * @param way2 A way that may have duplicate nodes with way1
* @return A map of node -> node(s) duplicates * @return A map of node -&gt; node(s) duplicates
*/ */
public static Map<Pair<Integer, Node>, Map<Integer, Node>> getDuplicateNodes(Way way1, Way way2) { public static Map<Pair<Integer, Node>, Map<Integer, Node>> getDuplicateNodes(Way way1, Way way2) {
final Map<Pair<Integer, Node>, Map<Integer, Node>> duplicateNodes = new LinkedHashMap<>(); final Map<Pair<Integer, Node>, Map<Integer, Node>> duplicateNodes = new LinkedHashMap<>();