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.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">
<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"/>

Wyświetl plik

@ -20,6 +20,7 @@ import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.Notification;
import org.openstreetmap.josm.gui.layer.Layer;
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
import org.openstreetmap.josm.tools.Shortcut;
@ -39,8 +40,26 @@ public class MapWithAIAction extends JosmAction {
@Override
public void actionPerformed(ActionEvent event) {
if (isEnabled()) {
MapWithAIDataUtils.getMapWithAIData(MapWithAIDataUtils.getLayer(true));
createMessageDialog();
final boolean hasLayer = MapWithAIDataUtils.getLayer(false) != null;
if (MapWithAIDataUtils.getMapWithAIData(MapWithAIDataUtils.getLayer(true))) {
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,15 +182,20 @@ public final class MapWithAIDataUtils {
* Get data for a {@link MapWithAILayer}
*
* @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)
.stream().filter(obj -> !MapWithAILayer.class.isInstance(obj)).collect(Collectors.toList());
boolean gotData = false;
for (final OsmDataLayer osmLayer : osmLayers) {
if (!osmLayer.isLocked()) {
getMapWithAIData(layer, osmLayer);
if (getMapWithAIData(layer, osmLayer)) {
gotData = true;
}
}
}
return gotData;
}
/**
@ -198,9 +203,10 @@ public final class MapWithAIDataUtils {
*
* @param layer A pre-existing {@link MapWithAILayer}
* @param osmLayer The osm datalayer with a set of bounds
* @return true if data was downloaded
*/
public static void getMapWithAIData(MapWithAILayer layer, OsmDataLayer osmLayer) {
getMapWithAIData(layer,
public static boolean getMapWithAIData(MapWithAILayer layer, OsmDataLayer osmLayer) {
return getMapWithAIData(layer,
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 bboxes The bboxes to get the data in
* @return true if data was downloaded
*/
public static void getMapWithAIData(MapWithAILayer layer, BBox... bboxes) {
getMapWithAIData(layer, Arrays.asList(bboxes));
public static boolean getMapWithAIData(MapWithAILayer layer, BBox... bboxes) {
return getMapWithAIData(layer, Arrays.asList(bboxes));
}
/**
@ -219,8 +226,9 @@ public final class MapWithAIDataUtils {
*
* @param layer A pre-existing {@link MapWithAILayer}
* @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 List<BBox> mapWithAIBounds = mapWithAISet.getDataSourceBounds().stream().map(Bounds::toBBox)
.collect(Collectors.toList());
@ -228,16 +236,19 @@ public final class MapWithAIDataUtils {
.filter(bbox -> mapWithAIBounds.stream().noneMatch(tBBox -> tBBox.bounds(bbox)))
.collect(Collectors.toList());
final List<BBox> toDownload = reduceBBox(mapWithAIBounds, editSetBBoxes);
getForkJoinPool().execute(() -> {
final DataSet newData = getData(toDownload);
final Lock lock = layer.getLock();
lock.lock();
try {
layer.mergeFrom(newData);
} finally {
lock.unlock();
}
});
if (!toDownload.isEmpty()) {
getForkJoinPool().execute(() -> {
final DataSet newData = getData(toDownload);
final Lock lock = layer.getLock();
lock.lock();
try {
layer.mergeFrom(newData);
} finally {
lock.unlock();
}
});
}
return !toDownload.isEmpty();
}
private static List<BBox> reduceBBox(List<BBox> alreadyDownloaded, List<BBox> wantToDownload) {

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() {
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 progressMonitor the progress monitor. If null, {@link NullProgressMonitor#INSTANCE} is assumed
* @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
* @throws IllegalDataException if an error was found while parsing the data from the source

Wyświetl plik

@ -117,8 +117,8 @@ public class MergeDuplicateWays extends Command {
/**
* Check for ways that are (partial) duplicates, and if so merge them
*
* @param way A way to check
* @return non-null command if there are duplicate ways
* @param way A way to check
* @param commands A list of commands to add to
*/
public static void checkForDuplicateWays(Way way, List<Command> commands) {
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 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) {
final Map<Pair<Integer, Node>, Map<Integer, Node>> duplicateNodes = new LinkedHashMap<>();