Changeset 5423 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2012-08-11T18:22:45+02:00 (12 years ago)
Author:
bastiK
Message:

doc + cosmetics (see #7948)

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/FilterMatcher.java

    r5170 r5423  
    66import java.util.List;
    77
     8import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;
    89import org.openstreetmap.josm.actions.search.SearchCompiler;
    9 import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;
    1010import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
    1111import org.openstreetmap.josm.actions.search.SearchCompiler.Not;
    1212import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
    1313
     14/**
     15 * Class that encapsulates the filter logic, i.e. applies a list of
     16 * filters to a primitive.
     17 *
     18 * Uses {@link SearchCompiler.Match#match} to see if the filter expression matches,
     19 * cares for "inverted-flag" of the filters and combines the results of all active
     20 * filters.
     21 *
     22 * There are two major use cases:
     23 *
     24 * (1) Hide features that you don't like to edit but get in the way, e.g.
     25 * <code>landuse</code> or power lines. It is expected, that the inverted flag
     26 * if false for these kind of filters.
     27 *
     28 * (2) Highlight certain features, that are currently interesting and hide everything
     29 * else. This can be thought of as an improved search (Ctrl-F), where you can
     30 * continue editing and don't loose the current selection. It is expected that
     31 * the inverted flag of the filter is true in this case.
     32 *
     33 * In addition to the formal application of filter rules, some magic is applied
     34 * to (hopefully) match the expectations of the user:
     35 *
     36 * (1) non-inverted: When hiding a way, all its untagged nodes are hidden as well.
     37 * This avoids a "cloud of nodes", that normally isn't useful without the
     38 * corresponding way.
     39 *
     40 * (2) inverted: When displaying a way, we show all its nodes, although the
     41 * individual nodes do not match the filter expression. The reason is, that a
     42 * way without its nodes cannot be edited properly.
     43 *
     44 */
    1445public class FilterMatcher {
    1546
     
    106137
    107138        boolean selected = false;
    108         boolean onlyInvertedFilters = true;
     139        // If the primitive is "explicitly" hidden by a non-inverted filter.
     140        // Only interesting for nodes.
     141        boolean explicitlyHidden = false;
    109142
    110143        for (FilterInfo fi: filters) {
    111             if (fi.isDelete && selected && fi.match.match(primitive)) {
    112                 selected = false;
    113             } else if (!fi.isDelete && (!selected || (onlyInvertedFilters && !fi.isInverted)) && fi.match.match(primitive)) {
    114                 selected = true;
    115                 onlyInvertedFilters = onlyInvertedFilters && fi.isInverted;
     144            if (fi.isDelete) {
     145                if (selected && fi.match.match(primitive)) {
     146                    selected = false;
     147                }
     148            } else {
     149                if ((!selected || (!explicitlyHidden && !fi.isInverted)) && fi.match.match(primitive)) {
     150                    selected = true;
     151                    if (!fi.isInverted) {
     152                        explicitlyHidden = true;
     153                    }
     154                }
    116155            }
    117156        }
    118157
    119158        if (primitive instanceof Node) {
     159            // Technically not hidden by any filter, but we hide it anyway, if
     160            // it is untagged and all parent ways are hidden.
    120161            if (!selected)
    121162                return !primitive.isTagged() && allParentWaysFiltered(primitive, hidden);
    122             if (onlyInvertedFilters)
    123                 return selected && !oneParentWayNotFiltered(primitive, hidden);
     163            // At this point, selected == true, so the node is hidden.
     164            // However, if there is a parent way, that is not hidden, we ignore
     165            // this and show the node anyway, unless there is no non-inverted
     166            // filter that applies to the node directly.
     167            if (!explicitlyHidden)
     168                return !oneParentWayNotFiltered(primitive, hidden);
    124169            return true;
    125170        } else
  • trunk/src/org/openstreetmap/josm/data/osm/FilterWorker.java

    r3719 r5423  
    1212     * Apply the filters to the primitives of the data set.
    1313     *
    14      * There are certain rules to ensure that a way is not displayed "naked"
    15      * without its nodes (1) and on the other hand to avoid hiding a way but
    16      * leaving its nodes visible as a cloud of points (2).
    17      *
    18      * In normal (non-inverted) mode only problem (2) is relevant.
    19      * Untagged child nodes of filtered ways that are not used by other
    20      * unfiltered ways are filtered as well.
    21      *
    22      * If a filter applies explicitly to a node, (2) is ignored and it
    23      * is filtered in any case.
    24      *
    25      * In inverted mode usually only problem (1) is relevant.
    26      * If the inverted filter applies explicitly to a node, this no longer
    27      * means it is filtered in any case:
    28      * E.g. the filter [searchtext="highway=footway", inverted=true] displays
    29      * the footways only. But that does not mean, the nodes of the footway
    30      * (which do not have the highway tag) should be filtered as well.
    31      *
    32      * So first the Filter is applied for ways and relations. Then to nodes
    33      * (but hides them only if they are not used by any unfiltered way).
     14     * @param all the collection of primitives for that the filter state should
     15     * be updated
     16     * @param filterMatcher the FilterMatcher
     17     * @return true, if the filter state of any primitive has changed in the process
    3418     */
    3519    public static boolean executeFilters(Collection<OsmPrimitive> all, FilterMatcher filterMatcher) {
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r5266 r5423  
    428428
    429429    /**
    430      * Make the primitive disabled (e.g. if a filter applies).
     430     * Make the primitive disabled (e.g.&nbsp;if a filter applies).
     431     *
    431432     * To enable the primitive again, use unsetDisabledState.
    432433     * @param hide if the primitive should be completely hidden from view or
    433434     *             just shown in gray color.
     435     * @return true, any flag has changed; false if you try to set the disabled
     436     * state to the value that is already preset
    434437     */
    435438    public boolean setDisabledState(boolean hide) {
Note: See TracChangeset for help on using the changeset viewer.