diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIMoveAction.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIMoveAction.java index 888e77c..8a20358 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIMoveAction.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIMoveAction.java @@ -69,13 +69,14 @@ public class MapWithAIMoveAction extends JosmAction { .collect(Collectors.toList()); ds.clearSelection(nodes); nodes.stream().map(Node::getReferrers).forEach(ds::addSelected); - if (ds.getSelected().size() > maxAddition) { + if (ds.getSelected().size() > maxAddition && !(maxAddition == 0 && ExpertToggleAction.isExpert())) { createMaxAddedDialog(maxAddition, ds.getSelected().size()); } final Collection selected = limitCollection(ds, maxAddition); final OsmDataLayer editLayer = getOsmDataLayer(); if (editLayer != null && !selected.isEmpty() - && MapWithAIDataUtils.getAddedObjects() < maxAddition * MAX_ADD_MULTIPLIER) { + && (MapWithAIDataUtils.getAddedObjects() < maxAddition * MAX_ADD_MULTIPLIER) + || (maxAddition == 0 && ExpertToggleAction.isExpert())) { final MapWithAIAddCommand command = new MapWithAIAddCommand(mapWithAI, editLayer, selected); UndoRedoHandler.getInstance().add(command); if (MapWithAIPreferenceHelper.isSwitchLayers()) { @@ -103,7 +104,12 @@ public class MapWithAIMoveAction extends JosmAction { : ds.getSelected(); } - private static OsmDataLayer getOsmDataLayer() { + /** + * Get the OSM Data Layer to add MapWithAI data to + * + * @return An OSM data layer that data can be added to + */ + public static OsmDataLayer getOsmDataLayer() { return MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream() .filter(OsmDataLayer::isVisible).filter(OsmDataLayer::isUploadable) .filter(osmLayer -> !osmLayer.isLocked() && osmLayer.getClass().equals(OsmDataLayer.class)).findFirst() diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddCommand.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddCommand.java index 687c468..91b889c 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddCommand.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddCommand.java @@ -6,6 +6,7 @@ import static org.openstreetmap.josm.tools.I18n.tr; import java.awt.EventQueue; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -17,7 +18,9 @@ import org.openstreetmap.josm.command.Command; import org.openstreetmap.josm.command.SequenceCommand; import org.openstreetmap.josm.data.UndoRedoHandler; import org.openstreetmap.josm.data.osm.DataSet; +import org.openstreetmap.josm.data.osm.Node; import org.openstreetmap.josm.data.osm.OsmPrimitive; +import org.openstreetmap.josm.data.osm.Way; import org.openstreetmap.josm.gui.layer.OsmDataLayer; import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin; import org.openstreetmap.josm.plugins.mapwithai.backend.GetDataRunnable; @@ -58,7 +61,11 @@ public class MapWithAIAddCommand extends Command implements Runnable { super(mapWithAI); this.mapWithAI = mapWithAI; this.editable = editable; - this.primitives = selection; + Collection nodeReferrers = selection.parallelStream().filter(Node.class::isInstance).map(Node.class::cast) + .map(Node::getReferrers).flatMap(List::stream).filter(Way.class::isInstance).map(Way.class::cast) + .collect(Collectors.toList()); + this.primitives = new HashSet<>(selection); + this.primitives.addAll(nodeReferrers); sources = selection.parallelStream() .map(prim -> new Pair(prim, prim.get(GetDataRunnable.MAPWITHAI_SOURCE_TAG_KEY))) .filter(pair -> pair.b != null).collect(Collectors.toMap(pair -> pair.a, pair -> pair.b));