source: josm/trunk/src/org/openstreetmap/josm/data/osm/FilterWorker.java@ 3715

Last change on this file since 3715 was 3471, checked in by jttt, 14 years ago

Fix #5379 Fixing duplicate nodes very slow when filter dock is open

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1package org.openstreetmap.josm.data.osm;
2
3import java.util.Collection;
4
5/**
6 *
7 * @author Petr_Dlouhý
8 */
9public class FilterWorker {
10 /**
11 * Apply the filters to the primitives of the data set.
12 *
13 * There are certain rules to ensure that a way is not displayed "naked"
14 * without its nodes (1) and on the other hand to avoid hiding a way but
15 * leaving its nodes visible as a cloud of points (2).
16 *
17 * In normal (non-inverted) mode only problem (2) is relevant.
18 * Untagged child nodes of filtered ways that are not used by other
19 * unfiltered ways are filtered as well.
20 *
21 * If a filter applies explicitly to a node, (2) is ignored and it
22 * is filtered in any case.
23 *
24 * In inverted mode usually only problem (1) is relevant.
25 * If the inverted filter applies explicitly to a node, this no longer
26 * means it is filtered in any case:
27 * E.g. the filter [searchtext="highway=footway", inverted=true] displays
28 * the footways only. But that does not mean, the nodes of the footway
29 * (which do not have the highway tag) should be filtered as well.
30 *
31 * So first the Filter is applied for ways and relations. Then to nodes
32 * (but hides them only if they are not used by any unfiltered way).
33 */
34 public static boolean executeFilters(Collection<OsmPrimitive> all, FilterMatcher filterMatcher) {
35
36 boolean changed = false;
37
38 // First relation and ways
39 for (OsmPrimitive primitive: all) {
40 if (!(primitive instanceof Node)) {
41 if (filterMatcher.isHidden(primitive)) {
42 changed = changed | primitive.setDisabledState(true);
43 } else if (filterMatcher.isDisabled(primitive)) {
44 changed = changed | primitive.setDisabledState(false);
45 } else {
46 changed = changed | primitive.unsetDisabledState();
47 }
48 }
49 }
50
51 // Then nodes (because they state may depend on parent ways)
52 for (OsmPrimitive primitive: all) {
53 if (primitive instanceof Node) {
54 if (filterMatcher.isHidden(primitive)) {
55 changed = changed | primitive.setDisabledState(true);
56 } else if (filterMatcher.isDisabled(primitive)) {
57 changed = changed | primitive.setDisabledState(false);
58 } else {
59 changed = changed | primitive.unsetDisabledState();
60 }
61 }
62 }
63
64 return changed;
65 }
66
67 public static boolean executeFilters(OsmPrimitive primitive, FilterMatcher filterMatcher) {
68 boolean changed = false;
69 if (filterMatcher.isHidden(primitive)) {
70 changed = changed | primitive.setDisabledState(true);
71 } else if (filterMatcher.isDisabled(primitive)) {
72 changed = changed | primitive.setDisabledState(false);
73 } else {
74 changed = changed | primitive.unsetDisabledState();
75 }
76 return changed;
77 }
78
79 public static void clearFilterFlags(Collection<OsmPrimitive> prims) {
80 for (OsmPrimitive osm : prims) {
81 osm.unsetDisabledState();
82 }
83 }
84}
Note: See TracBrowser for help on using the repository browser.