kopia lustrzana https://github.com/JOSM/MapWithAI
Fix some race conditions with EDT threads
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
0c522d932c
commit
cbde7fb181
|
@ -4,6 +4,7 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
|
|||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -16,6 +17,8 @@ import java.util.TreeMap;
|
|||
import java.util.concurrent.RecursiveTask;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.openstreetmap.josm.actions.MergeNodesAction;
|
||||
import org.openstreetmap.josm.command.Command;
|
||||
import org.openstreetmap.josm.command.DeleteCommand;
|
||||
|
@ -125,17 +128,26 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
|
|||
* @param bounds
|
||||
*/
|
||||
public static void cleanup(DataSet dataSet, Bounds bounds) {
|
||||
synchronized (LOCK) {
|
||||
removeRedundantSource(dataSet);
|
||||
replaceTags(dataSet);
|
||||
removeCommonTags(dataSet);
|
||||
mergeNodes(dataSet);
|
||||
cleanupDataSet(dataSet);
|
||||
mergeWays(dataSet);
|
||||
removeAlreadyAddedData(dataSet);
|
||||
new MergeDuplicateWays(dataSet).executeCommand();
|
||||
(bounds == null ? dataSet.getWays() : dataSet.searchWays(bounds.toBBox())).parallelStream()
|
||||
.filter(way -> !way.isDeleted()).forEach(GetDataRunnable::cleanupArtifacts);
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
synchronized (LOCK) {
|
||||
removeRedundantSource(dataSet);
|
||||
replaceTags(dataSet);
|
||||
removeCommonTags(dataSet);
|
||||
mergeNodes(dataSet);
|
||||
cleanupDataSet(dataSet);
|
||||
mergeWays(dataSet);
|
||||
removeAlreadyAddedData(dataSet);
|
||||
new MergeDuplicateWays(dataSet).executeCommand();
|
||||
(bounds == null ? dataSet.getWays() : dataSet.searchWays(bounds.toBBox())).parallelStream()
|
||||
.filter(way -> !way.isDeleted()).forEach(GetDataRunnable::cleanupArtifacts);
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
Logging.debug(e);
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (InvocationTargetException e) {
|
||||
Logging.debug(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.openstreetmap.josm.plugins.mapwithai.backend.commands.conflation;
|
|||
|
||||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -10,6 +11,8 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.openstreetmap.josm.command.ChangePropertyCommand;
|
||||
import org.openstreetmap.josm.command.Command;
|
||||
import org.openstreetmap.josm.command.DeleteCommand;
|
||||
|
@ -22,6 +25,7 @@ import org.openstreetmap.josm.data.osm.Relation;
|
|||
import org.openstreetmap.josm.data.osm.Way;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIPreferenceHelper;
|
||||
import org.openstreetmap.josm.tools.Geometry;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
public class MergeBuildingAddress extends AbstractConflationCommand {
|
||||
public static final String KEY = "addr:housenumber";
|
||||
|
@ -66,9 +70,18 @@ public class MergeBuildingAddress extends AbstractConflationCommand {
|
|||
private static Collection<Command> mergeBuildingAddress(DataSet affectedDataSet, Node node) {
|
||||
final List<OsmPrimitive> toCheck = new ArrayList<>();
|
||||
final BBox bbox = new BBox(node.getCoor().getX(), node.getCoor().getY(), 0.001);
|
||||
toCheck.addAll(affectedDataSet.searchWays(bbox));
|
||||
toCheck.addAll(affectedDataSet.searchRelations(bbox));
|
||||
toCheck.addAll(affectedDataSet.searchNodes(bbox));
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
toCheck.addAll(affectedDataSet.searchWays(bbox));
|
||||
toCheck.addAll(affectedDataSet.searchRelations(bbox));
|
||||
toCheck.addAll(affectedDataSet.searchNodes(bbox));
|
||||
});
|
||||
} catch (InvocationTargetException e) {
|
||||
Logging.debug(e);
|
||||
} catch (InterruptedException e) {
|
||||
Logging.debug(e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
List<OsmPrimitive> possibleDuplicates = toCheck.parallelStream().filter(prim -> prim.hasTag(KEY))
|
||||
.filter(prim -> prim.get(KEY).equals(node.get(KEY))).filter(prim -> !prim.equals(node))
|
||||
.collect(Collectors.toList());
|
||||
|
|
Ładowanie…
Reference in New Issue