Changeset 4318 in josm for trunk


Ignore:
Timestamp:
2011-08-15T18:53:30+02:00 (13 years ago)
Author:
bastiK
Message:

mapcss: allow disabling the default point- and line styles

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r4180 r4318  
    2424    private boolean drawMultipolygon;
    2525
    26     private int cacheIdx;
     26    private int cacheIdx = 1;
     27
     28    private boolean defaultNodes, defaultLines;
     29    private int defaultNodesIdx, defaultLinesIdx;
    2730
    2831    public ElemStyles()
     
    3942    }
    4043
     44    /**
     45     * Create the list of styles for one primitive.
     46     *
     47     * @param osm the primitive
     48     * @param scale the scale (in meters per 100 pixel)
     49     * @param nc
     50     * @return
     51     */
    4152    public StyleList get(OsmPrimitive osm, double scale, NavigatableComponent nc) {
    4253        return getStyleCacheWithRange(osm, scale, nc).a;
    4354    }
    4455
     56    /**
     57     * Create the list of styles and its valid scale range for one primitive.
     58     *
     59     * Automatically adds default styles in case no proper style was found.
     60     * Uses the cache, if possible, and saves the results to the cache.
     61     */
    4562    public Pair<StyleList, Range> getStyleCacheWithRange(OsmPrimitive osm, double scale, NavigatableComponent nc) {
    4663        if (osm.mappaintStyle == null || osm.mappaintCacheIdx != cacheIdx) {
     
    5269        }
    5370        Pair<StyleList, Range> p = getImpl(osm, scale, nc);
    54         if (osm instanceof Node) {
     71        if (osm instanceof Node && isDefaultNodes()) {
    5572            boolean hasNonModifier = false;
    5673            for (ElemStyle s : p.a) {
     
    6380                p.a = new StyleList(p.a, NodeElemStyle.SIMPLE_NODE_ELEMSTYLE);
    6481            }
    65         } else if (osm instanceof Way) {
     82        } else if (osm instanceof Way && isDefaultLines()) {
    6683            boolean hasProperLineStyle = false;
    6784            for (ElemStyle s : p.a) {
     
    7390            if (!hasProperLineStyle) {
    7491                AreaElemStyle area = Utils.find(p.a, AreaElemStyle.class);
    75                 LineElemStyle line = (area == null ? LineElemStyle.UNTAGGED_WAY : LineElemStyle.createSimpleLineStyle(area.color, true));
     92                LineElemStyle line = null;
     93                line = (area == null ? LineElemStyle.UNTAGGED_WAY : LineElemStyle.createSimpleLineStyle(area.color, true));
    7694                p.a = new StyleList(p.a, line);
    7795            }
     
    82100    }
    83101
     102    /**
     103     * Create the list of styles and its valid scale range for one primitive.
     104     *
     105     * This method does multipolygon handling.
     106     *
     107     *
     108     * There are different tagging styles for multipolygons, that have to be respected:
     109     * - tags on the relation
     110     * - tags on the outer way
     111     * - tags on both, the outer and the inner way (very old style)
     112     *
     113     * If the primitive is a way, look for multipolygon parents. In case it
     114     * is indeed member of some multipolygon as role "outer", all area styles
     115     * are removed. (They apply to the multipolygon area.)
     116     * Outer ways can have their own independent line styles, e.g. a road as
     117     * boundary of a forest. Otherwise, in case, the way does not have an
     118     * independent line style, take a line style from the multipolygon.
     119     * If the multipolygon does not have a line style either, at least create a
     120     * default line style from the color of the area.
     121     *
     122     * Now consider the case that the way is not an outer way of any multipolygon,
     123     * but is member of a multipolygon as "inner".
     124     * First, the style list is regenerated, considering only tags of this way
     125     * minus the tags of outer way of the multipolygon (to care for the "very
     126     * old style").
     127     * Then check, if the way describes something in its own right. (linear feature
     128     * or area) If not, add a default line style from the area color of the multipolygon.
     129     *
     130     */
    84131    private Pair<StyleList, Range> getImpl(OsmPrimitive osm, double scale, NavigatableComponent nc) {
    85132        if (osm instanceof Node)
     
    131178                            p.b = Range.cut(p.b, mpElemStyles.b);
    132179                            break;
    133                         } else if (wayColor == null) {
     180                        } else if (wayColor == null && isDefaultLines()) {
    134181                            AreaElemStyle mpArea = Utils.find(mpElemStyles.a, AreaElemStyle.class);
    135182                            if (mpArea != null) {
     
    142189            }
    143190            if (isOuterWayOfSomeMP) {
    144                 boolean hasLineStyle = false;
    145                 for (ElemStyle s : p.a) {
    146                     if (s.isProperLineStyle()) {
    147                         hasLineStyle = true;
    148                         break;
    149                     }
    150                 }
    151                 if (!hasLineStyle) {
    152                     p.a = new StyleList(p.a, LineElemStyle.createSimpleLineStyle(wayColor, true));
     191                if (isDefaultLines()) {
     192                    boolean hasLineStyle = false;
     193                    for (ElemStyle s : p.a) {
     194                        if (s.isProperLineStyle()) {
     195                            hasLineStyle = true;
     196                            break;
     197                        }
     198                    }
     199                    if (!hasLineStyle) {
     200                        p.a = new StyleList(p.a, LineElemStyle.createSimpleLineStyle(wayColor, true));
     201                    }
    153202                }
    154203                return p;
    155204            }
     205
     206            if (!isDefaultLines()) return p;
    156207
    157208            for (OsmPrimitive referrer : osm.getReferrers()) {
     
    213264
    214265    /**
     266     * Create the list of styles and its valid scale range for one primitive.
     267     *
     268     * Loops over the list of style sources, to generate the map of properties.
     269     * From these properties, it generates the different types of styles.
     270     *
    215271     * @param multipolyOuterWay support for a very old multipolygon tagging style
    216272     * where you add the tags both to the outer and the inner way.
     
    268324    }
    269325
     326    /**
     327     * Draw a default node symbol for nodes that have no style?
     328     */
     329    private boolean isDefaultNodes() {
     330        if (defaultNodesIdx == cacheIdx) {
     331            return defaultNodes;
     332        }
     333        defaultNodes = fromCanvas("default-points", true, Boolean.class);
     334        defaultNodesIdx = cacheIdx;
     335        return defaultNodes;
     336    }
     337
     338    /**
     339     * Draw a default line for ways that do not have an own line style?
     340     */
     341    private boolean isDefaultLines() {
     342        if (defaultLinesIdx == cacheIdx) {
     343            return defaultLines;
     344        }
     345        defaultLines = fromCanvas("default-lines", true, Boolean.class);
     346        defaultLinesIdx = cacheIdx;
     347        return defaultLines;
     348    }
     349
     350    private <T> T fromCanvas(String key, T def, Class<T> c) {
     351        MultiCascade mc = new MultiCascade();
     352        Relation r = new Relation();
     353        r.put("#canvas", "query");
     354
     355        for (StyleSource s : styleSources) {
     356            if (s.active) {
     357                s.apply(mc, r, 1, null, false);
     358            }
     359        }
     360        T res = mc.getCascade("default").get(key, def, c);
     361        return res;
     362    }
     363
    270364    public boolean isDrawMultipolygon() {
    271365        return drawMultipolygon;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r4272 r4318  
    164164    }
    165165
    166     private static NodeElemStyle create(Environment env, boolean allowOnlyText) {
     166    private static NodeElemStyle create(Environment env, boolean allowDefault) {
    167167        initDefaultParameters();
    168168        Cascade c = env.mc.getCascade(env.layer);
     
    175175
    176176        NodeTextElement text = null;
    177         TextElement te = TextElement.create(c, DEFAULT_TEXT_COLOR, symbol == null && icon == null);
     177        TextElement te = TextElement.create(c, DEFAULT_TEXT_COLOR, symbol == null && icon == null && allowDefault);
    178178        // optimization: if we neither have a symbol, nor an icon, nor a text element
    179179        // we don't have to check for the remaining style properties and we don't
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r4191 r4318  
    265265
    266266        public boolean matchesBase(Environment e){
    267             if (base.equals("*"))
    268                 return true;
    269             if (base.equals("area")) {
    270                 if (e.osm instanceof Way)
     267            if (e.osm instanceof Node) {
     268                return base.equals("node") || base.equals("*");
     269            } else if (e.osm instanceof Way) {
     270                return base.equals("way") || base.equals("area") || base.equals("*");
     271            } else if (e.osm instanceof Relation) {
     272                if (base.equals("area")) {
     273                    return ((Relation) e.osm).isMultipolygon();
     274                } else if (base.equals("relation")) {
    271275                    return true;
    272                 if (e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon())
    273                     return true;
    274             }
    275             if (base.equals(OsmPrimitiveType.from(e.osm).getAPIName()))
    276                 return true;
     276                } else if (base.equals("canvas")) {
     277                    return e.osm.get("#canvas") != null;
     278                }
     279            }
    277280            return false;
    278281        }
Note: See TracChangeset for help on using the changeset viewer.