kopia lustrzana https://github.com/JOSM/MapWithAI
Add ProgressMonitor dialogs
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
c75760c35b
commit
d937c1046e
|
@ -22,8 +22,7 @@ public class RapiDAction extends JosmAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
final RapiDLayer layer = RapiDDataUtils.getLayer(true);
|
RapiDDataUtils.getRapiDData(RapiDDataUtils.getLayer(true));
|
||||||
RapiDDataUtils.getRapiDData(layer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,7 +20,6 @@ import org.openstreetmap.josm.actions.JosmAction;
|
||||||
import org.openstreetmap.josm.data.Bounds;
|
import org.openstreetmap.josm.data.Bounds;
|
||||||
import org.openstreetmap.josm.data.coor.LatLon;
|
import org.openstreetmap.josm.data.coor.LatLon;
|
||||||
import org.openstreetmap.josm.data.osm.BBox;
|
import org.openstreetmap.josm.data.osm.BBox;
|
||||||
import org.openstreetmap.josm.data.osm.DataSet;
|
|
||||||
import org.openstreetmap.josm.gui.ExtendedDialog;
|
import org.openstreetmap.josm.gui.ExtendedDialog;
|
||||||
import org.openstreetmap.josm.gui.MainApplication;
|
import org.openstreetmap.josm.gui.MainApplication;
|
||||||
import org.openstreetmap.josm.gui.MapView;
|
import org.openstreetmap.josm.gui.MapView;
|
||||||
|
@ -129,17 +128,7 @@ public class RapiDArbitraryAction extends JosmAction {
|
||||||
DetectTaskingManagerUtils.createTaskingManagerGpxData(bbox), DetectTaskingManagerUtils.RAPID_CROP_AREA));
|
DetectTaskingManagerUtils.createTaskingManagerGpxData(bbox), DetectTaskingManagerUtils.RAPID_CROP_AREA));
|
||||||
}
|
}
|
||||||
|
|
||||||
final DataSet data = RapiDDataUtils.getData(bbox);
|
RapiDDataUtils.getRapiDData(RapiDDataUtils.getLayer(true), bbox);
|
||||||
final RapiDLayer layer = RapiDDataUtils.getLayer(true);
|
|
||||||
final DataSet rapidData = layer.getDataSet();
|
|
||||||
boolean locked = rapidData.isLocked();
|
|
||||||
if (locked) {
|
|
||||||
rapidData.unlock();
|
|
||||||
}
|
|
||||||
rapidData.mergeFrom(data);
|
|
||||||
if (locked) {
|
|
||||||
rapidData.lock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBounds(Bounds b) {
|
private void setBounds(Bounds b) {
|
||||||
|
|
|
@ -11,8 +11,9 @@ import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.openstreetmap.josm.data.Bounds;
|
import org.openstreetmap.josm.data.Bounds;
|
||||||
import org.openstreetmap.josm.data.coor.LatLon;
|
import org.openstreetmap.josm.data.coor.LatLon;
|
||||||
|
@ -29,6 +30,7 @@ import org.openstreetmap.josm.data.preferences.sources.SourceEntry;
|
||||||
import org.openstreetmap.josm.data.preferences.sources.SourceType;
|
import org.openstreetmap.josm.data.preferences.sources.SourceType;
|
||||||
import org.openstreetmap.josm.gui.MainApplication;
|
import org.openstreetmap.josm.gui.MainApplication;
|
||||||
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
||||||
|
import org.openstreetmap.josm.gui.progress.swing.PleaseWaitProgressMonitor;
|
||||||
import org.openstreetmap.josm.io.IllegalDataException;
|
import org.openstreetmap.josm.io.IllegalDataException;
|
||||||
import org.openstreetmap.josm.io.OsmReader;
|
import org.openstreetmap.josm.io.OsmReader;
|
||||||
import org.openstreetmap.josm.plugins.rapid.RapiDPlugin;
|
import org.openstreetmap.josm.plugins.rapid.RapiDPlugin;
|
||||||
|
@ -81,20 +83,23 @@ public final class RapiDDataUtils {
|
||||||
public static DataSet getData(BBox bbox) {
|
public static DataSet getData(BBox bbox) {
|
||||||
final DataSet dataSet = new DataSet();
|
final DataSet dataSet = new DataSet();
|
||||||
if (bbox.isValid()) {
|
if (bbox.isValid()) {
|
||||||
final List<Future<?>> futures = new ArrayList<>();
|
final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor();
|
||||||
for (final BBox tbbox : reduceBBoxSize(bbox)) {
|
monitor.setCancelable(Boolean.FALSE);
|
||||||
futures.add(MainApplication.worker.submit(new GetDataRunnable(tbbox, dataSet)));
|
final List<BBox> bboxes = reduceBBoxSize(bbox);
|
||||||
|
monitor.beginTask(tr("Downloading {0} data", RapiDPlugin.NAME), bboxes.size());
|
||||||
|
final ForkJoinPool pool = new ForkJoinPool();
|
||||||
|
for (final BBox tbbox : bboxes) {
|
||||||
|
pool.submit(new GetDataRunnable(tbbox, dataSet, monitor));
|
||||||
}
|
}
|
||||||
for (final Future<?> future : futures) {
|
pool.shutdown();
|
||||||
try {
|
try {
|
||||||
future.get();
|
pool.awaitTermination(10, TimeUnit.SECONDS);
|
||||||
} catch (final InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Logging.debug(e);
|
Logging.debug(e);
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} catch (ExecutionException e) {
|
|
||||||
Logging.debug(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
monitor.finishTask();
|
||||||
|
monitor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Microsoft buildings don't have a source, so we add one */
|
/* Microsoft buildings don't have a source, so we add one */
|
||||||
|
@ -105,10 +110,12 @@ public final class RapiDDataUtils {
|
||||||
private static class GetDataRunnable implements Runnable {
|
private static class GetDataRunnable implements Runnable {
|
||||||
private final BBox bbox;
|
private final BBox bbox;
|
||||||
private final DataSet dataSet;
|
private final DataSet dataSet;
|
||||||
|
private final PleaseWaitProgressMonitor monitor;
|
||||||
|
|
||||||
public GetDataRunnable(BBox bbox, DataSet dataSet) {
|
public GetDataRunnable(BBox bbox, DataSet dataSet, PleaseWaitProgressMonitor monitor) {
|
||||||
this.bbox = bbox;
|
this.bbox = bbox;
|
||||||
this.dataSet = dataSet;
|
this.dataSet = dataSet;
|
||||||
|
this.monitor = monitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -117,6 +124,7 @@ public final class RapiDDataUtils {
|
||||||
synchronized (RapiDDataUtils.GetDataRunnable.class) {
|
synchronized (RapiDDataUtils.GetDataRunnable.class) {
|
||||||
getDataSet().mergeFrom(temporaryDataSet);
|
getDataSet().mergeFrom(temporaryDataSet);
|
||||||
}
|
}
|
||||||
|
monitor.worked(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -420,6 +428,55 @@ public final class RapiDDataUtils {
|
||||||
return topLeft.greatCircleDistance(bottomLeft);
|
return topLeft.greatCircleDistance(bottomLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the data for RapiD
|
||||||
|
*
|
||||||
|
* @param layer A pre-existing {@link RapiDLayer}
|
||||||
|
* @param bboxes The bboxes to get the data in
|
||||||
|
*/
|
||||||
|
public static void getRapiDData(RapiDLayer layer, Collection<BBox> bboxes) {
|
||||||
|
final DataSet rapidSet = layer.getDataSet();
|
||||||
|
final List<BBox> rapidBounds = rapidSet.getDataSourceBounds().stream().map(Bounds::toBBox).collect(Collectors.toList());
|
||||||
|
final List<BBox> editSetBBoxes = bboxes.stream()
|
||||||
|
.filter(bbox -> rapidBounds.stream().noneMatch(tBBox -> tBBox.bounds(bbox)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
final ForkJoinPool pool = new ForkJoinPool();
|
||||||
|
for (final BBox bbox : editSetBBoxes) {
|
||||||
|
// TODO remove bounds that are already downloaded
|
||||||
|
if (rapidBounds.parallelStream().filter(bbox::bounds).count() == 0) {
|
||||||
|
pool.execute(() -> {
|
||||||
|
final DataSet newData = getData(bbox);
|
||||||
|
synchronized (LAYER_LOCK) {
|
||||||
|
layer.unlock();
|
||||||
|
try {
|
||||||
|
layer.mergeFrom(newData);
|
||||||
|
} finally {
|
||||||
|
layer.lock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pool.shutdown();
|
||||||
|
try {
|
||||||
|
pool.awaitTermination(10, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Logging.debug(e);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the data for RapiD
|
||||||
|
*
|
||||||
|
* @param layer A pre-existing {@link RapiDLayer}
|
||||||
|
* @param bboxes The bboxes to get the data in
|
||||||
|
*/
|
||||||
|
public static void getRapiDData(RapiDLayer layer, BBox... bboxes) {
|
||||||
|
getRapiDData(layer, Arrays.asList(bboxes));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the data for RapiD
|
* Get the data for RapiD
|
||||||
*
|
*
|
||||||
|
@ -427,21 +484,8 @@ public final class RapiDDataUtils {
|
||||||
* @param osmLayer The osm datalayer with a set of bounds
|
* @param osmLayer The osm datalayer with a set of bounds
|
||||||
*/
|
*/
|
||||||
public static void getRapiDData(RapiDLayer layer, OsmDataLayer osmLayer) {
|
public static void getRapiDData(RapiDLayer layer, OsmDataLayer osmLayer) {
|
||||||
final DataSet editSet = osmLayer.getDataSet();
|
getRapiDData(layer,
|
||||||
final List<Bounds> editSetBounds = editSet.getDataSourceBounds();
|
osmLayer.getDataSet().getDataSourceBounds().stream().map(Bounds::toBBox).collect(Collectors.toList()));
|
||||||
final DataSet rapidSet = layer.getDataSet();
|
|
||||||
final List<Bounds> rapidBounds = rapidSet.getDataSourceBounds();
|
|
||||||
for (final Bounds bound : editSetBounds) {
|
|
||||||
// TODO remove bounds that are already downloaded
|
|
||||||
if (rapidBounds.parallelStream().filter(bound::equals).count() == 0) {
|
|
||||||
final DataSet newData = getData(bound.toBBox());
|
|
||||||
synchronized (LAYER_LOCK) {
|
|
||||||
layer.unlock();
|
|
||||||
layer.mergeFrom(newData);
|
|
||||||
layer.lock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -93,16 +93,12 @@ public class RapiDRemoteControl extends RequestHandler.RawURLParseRequestHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
if (download != null && download.isInWorld()) {
|
if (download != null && download.isInWorld()) {
|
||||||
layer.getDataSet().unlock();
|
RapiDDataUtils.getRapiDData(layer, download);
|
||||||
layer.getDataSet().mergeFrom(RapiDDataUtils.getData(download));
|
|
||||||
layer.getDataSet().lock();
|
|
||||||
} else if (MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream()
|
} else if (MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream()
|
||||||
.filter(tLayer -> !(tLayer instanceof RapiDLayer)).count() != 0) {
|
.anyMatch(tLayer -> !(tLayer instanceof RapiDLayer))) {
|
||||||
RapiDDataUtils.getRapiDData(layer);
|
RapiDDataUtils.getRapiDData(layer);
|
||||||
} else if (crop != null && crop.isInWorld()) {
|
} else if (crop != null && crop.isInWorld()) {
|
||||||
layer.getDataSet().unlock();
|
RapiDDataUtils.getRapiDData(layer, crop);
|
||||||
layer.getDataSet().mergeFrom(RapiDDataUtils.getData(crop));
|
|
||||||
layer.getDataSet().lock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,20 +69,22 @@ public class RapiDAddCommand extends Command implements Runnable {
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
final boolean locked = rapid.isLocked();
|
final boolean locked = rapid.isLocked();
|
||||||
if (locked) {
|
try {
|
||||||
rapid.unlock();
|
if (locked) {
|
||||||
}
|
rapid.unlock();
|
||||||
final Command movePrimitivesCommand = new MovePrimitiveDataSetCommand(editable, rapid, primitives);
|
}
|
||||||
final List<OsmPrimitive> allPrimitives = new ArrayList<>();
|
final Command movePrimitivesCommand = new MovePrimitiveDataSetCommand(editable, rapid, primitives);
|
||||||
RapiDDataUtils.addPrimitivesToCollection(allPrimitives, primitives);
|
final List<OsmPrimitive> allPrimitives = new ArrayList<>();
|
||||||
final Command createConnectionsCommand = createConnections(editable, allPrimitives);
|
RapiDDataUtils.addPrimitivesToCollection(allPrimitives, primitives);
|
||||||
if (command == null) { // needed for undo/redo (don't create a new command)
|
final Command createConnectionsCommand = createConnections(editable, allPrimitives);
|
||||||
command = new SequenceCommand(getDescriptionText(), movePrimitivesCommand, createConnectionsCommand);
|
if (command == null) { // needed for undo/redo (don't create a new command)
|
||||||
}
|
command = new SequenceCommand(getDescriptionText(), movePrimitivesCommand, createConnectionsCommand);
|
||||||
command.executeCommand();
|
}
|
||||||
|
command.executeCommand();
|
||||||
if (locked) {
|
} finally {
|
||||||
rapid.lock();
|
if (locked) {
|
||||||
|
rapid.lock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,16 +104,19 @@ public class RapiDAddCommand extends Command implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void undoCommand() {
|
public void undoCommand() {
|
||||||
final boolean locked = rapid.isLocked();
|
final boolean locked = rapid.isLocked();
|
||||||
if (locked) {
|
try {
|
||||||
rapid.unlock();
|
if (locked) {
|
||||||
}
|
rapid.unlock();
|
||||||
synchronized (this) {
|
}
|
||||||
if (command != null) {
|
synchronized (this) {
|
||||||
command.undoCommand();
|
if (command != null) {
|
||||||
|
command.undoCommand();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (locked) {
|
||||||
|
rapid.lock();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (locked) {
|
|
||||||
rapid.lock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue