source: josm/trunk/src/org/openstreetmap/josm/actions/ValidateAction.java

Last change on this file was 18960, checked in by GerdP, 3 months ago

fix #23397: Improve the results of partial validations

  • pass also parent ways and relations of uploaded/selected objects to the testers, child objects are already added, this allows to find e.g. overlapping polygons problems with tags in members of relations
  • let CrossingWays find a problem if at least one of the crossing ways is in the partial selection.
  • let DuplicatWays find a problem if at least one of the duplicated ways is in the partial selection
  • add code to filter the detected issues so that those issues which are clearly not related to the original list of objects are removed. A few issues from mapcss tests may remain.
  • add new preference validator.partial.add.parents to disable the addition of parent objects, default is enabled
  • add new preference validator.partial.removeIrrelevant to disable the filtering of irrelevant errors, default is enabled
  • duplicated code to call AggregatePrimitivesVisitor was moved to ValidationTask
  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.util.Collection;
9import java.util.Optional;
10
11import org.openstreetmap.josm.data.osm.OsmPrimitive;
12import org.openstreetmap.josm.data.validation.OsmValidator;
13import org.openstreetmap.josm.data.validation.Test;
14import org.openstreetmap.josm.data.validation.ValidationTask;
15import org.openstreetmap.josm.gui.MainApplication;
16import org.openstreetmap.josm.gui.MapFrame;
17import org.openstreetmap.josm.tools.Shortcut;
18
19/**
20 * The action that does the validate thing.
21 * <p>
22 * This action iterates through all active tests and give them the data, so that
23 * each one can test it.
24 *
25 * @author frsantos
26 */
27public class ValidateAction extends JosmAction {
28
29 /** Last selection used to validate */
30 private transient Collection<OsmPrimitive> lastSelection;
31
32 /**
33 * Constructor
34 */
35 public ValidateAction() {
36 super(tr("Validation"), "dialogs/validator", tr("Performs the data validation"),
37 Shortcut.registerShortcut("tools:validate", tr("Validation"),
38 KeyEvent.VK_V, Shortcut.SHIFT), true);
39 }
40
41 @Override
42 public void actionPerformed(ActionEvent ev) {
43 doValidate(true);
44 }
45
46 /**
47 * Does the validation.
48 * <p>
49 * If getSelectedItems is true, the selected items (or all items, if no one
50 * is selected) are validated. If it is false, last selected items are revalidated
51 *
52 * @param getSelectedItems If selected or last selected items must be validated
53 */
54 public void doValidate(boolean getSelectedItems) {
55 MapFrame map = MainApplication.getMap();
56 if (map == null || !map.isVisible())
57 return;
58
59 OsmValidator.initializeTests();
60
61 Collection<Test> tests = OsmValidator.getEnabledTests(false);
62 if (tests.isEmpty())
63 return;
64
65 Collection<OsmPrimitive> selection;
66 if (getSelectedItems) {
67 selection = getLayerManager().getActiveDataSet().getAllSelected();
68 if (selection.isEmpty()) {
69 selection = getLayerManager().getActiveDataSet().allNonDeletedPrimitives();
70 lastSelection = null;
71 } else {
72 lastSelection = selection;
73 }
74 } else {
75 selection = Optional.ofNullable(lastSelection).orElseGet(
76 () -> getLayerManager().getActiveDataSet().allNonDeletedPrimitives());
77 }
78
79 MainApplication.worker.submit(new ValidationTask(tests, selection, lastSelection));
80 }
81
82 @Override
83 public void updateEnabledState() {
84 setEnabled(getLayerManager().getActiveDataSet() != null);
85 }
86
87 @Override
88 public void destroy() {
89 // Hack - this action should stay forever because it could be added to toolbar
90 // Do not call super.destroy() here
91 lastSelection = null;
92 }
93
94}
Note: See TracBrowser for help on using the repository browser.