Skip to content

Commit

Permalink
fix #23735: Combine ways refused
Browse files Browse the repository at this point in the history
(patch 23735-2.patch)
- rewrite check so that it checks if the parents of the combined ways are known instead of the parents of the connection node(s)
- show dialog with hint about download parents action that allows to continue

TODO: implement full automatic download of parents in all relavant action or add download button in the common dialog.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@19119 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
GerdP authored and GerdP committed Jun 20, 2024
1 parent a3c38ac commit 064ab0a
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/org/openstreetmap/josm/actions/CombineWayAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -279,20 +277,6 @@ public void actionPerformed(ActionEvent event) {
return;
}

// see #18083: check if we will combine ways at nodes outside of the download area
Set<Node> endNodesOutside = new HashSet<>();
for (Way w : selectedWays) {
final Node[] endnodes = {w.firstNode(), w.lastNode()};
for (Node n : endnodes) {
if (!n.isNew() && !n.isReferrersDownloaded() && !endNodesOutside.add(n)) {
new Notification(tr("Combine ways refused<br>" + "(A shared node may have additional referrers)"))
.setIcon(JOptionPane.INFORMATION_MESSAGE).show();
return;

}
}
}

// combine and update gui
Pair<Way, Command> combineResult;
try {
Expand All @@ -305,6 +289,10 @@ public void actionPerformed(ActionEvent event) {
if (combineResult == null)
return;

// see #18083: check if we will combine ways at nodes outside of the download area
if (!checkAndConfirmCombineOutlyingWays(selectedWays))
return;

final Way selectedWay = combineResult.a;
UndoRedoHandler.getInstance().add(combineResult.b);
Test test = new OverlappingWays();
Expand Down Expand Up @@ -346,4 +334,27 @@ protected void updateEnabledState(Collection<? extends OsmPrimitive> selection)
setEnabled(numWays >= 2);
}

/**
* Check whether user is about to combine ways with unknown parents.
* Request confirmation if he is.
* @param ways the primitives to operate on
* @return true, if operating on outlying primitives is OK; false, otherwise
*/
private static boolean checkAndConfirmCombineOutlyingWays(Collection<Way> ways) {
DownloadReferrersAction action = MainApplication.getMenu().downloadReferrers;
final String downloadHint = tr("You should use {0}->{1}({2}) first.",
MainApplication.getMenu().editMenu.getText(), action.getValue(NAME), action.getShortcut().toString());
return Boolean.TRUE.equals(GuiHelper.runInEDTAndWaitAndReturn(() -> checkAndConfirmOutlyingOperation("combine",
tr("Combine confirmation"),
tr("You are about to combine ways which can be members of relations not yet downloaded."
+ "<br>"
+ "This can lead to damaging these parent relations (that you do not see)."
+ "<br>"
+ "{0}"
+ "<br><br>"
+ "Do you really want to combine without downloading?", downloadHint),
"", // not used, we never combine incomplete ways
ways, Collections.emptyList())));
}

}

0 comments on commit 064ab0a

Please sign in to comment.