Ignore:
Timestamp:
2011-01-27T21:18:27+01:00 (13 years ago)
Author:
bastiK
Message:

Separate styles from style generation. This may seem a little over the top, but its just an intermediate state of development, should make sense later. Regarding performance: execution time is the same, memory use is similar, or a little less (due to intern pool for StyleCache). Tested, but can have still some bugs.

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

Legend:

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

    r3731 r3824  
    2626import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
    2727import org.openstreetmap.josm.data.osm.visitor.Visitor;
    28 import org.openstreetmap.josm.gui.mappaint.ElemStyle;
     28import org.openstreetmap.josm.gui.mappaint.StyleCache;
    2929import org.openstreetmap.josm.tools.CheckParameterUtil;
    3030import org.openstreetmap.josm.tools.Predicate;
     
    299299     * MAPPAINT
    300300     *--------*/
    301     public ElemStyle mappaintStyle = null;
     301    public StyleCache mappaintStyle = null;
    302302    public int mappaintDrawnCode = 0;
    303303
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintVisitor.java

    r3822 r3824  
    1 /* License: GPL. Copyright 2007 by Immanuel Scholz and others */
     1// License: GPL. Copyright 2007 by Immanuel Scholz and others
    22package org.openstreetmap.josm.data.osm.visitor.paint;
    3 
    4 /* To enable debugging or profiling remove the double / signs */
    53
    64import java.awt.Graphics2D;
     
    3836import org.openstreetmap.josm.gui.mappaint.LineElemStyle;
    3937import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    40 import org.openstreetmap.josm.gui.mappaint.SimpleNodeElemStyle;
     38import org.openstreetmap.josm.gui.mappaint.StyleCache;
    4139
    4240public class MapPaintVisitor implements PaintVisitor {
     
    7068    }
    7169
    72     public ElemStyle getPrimitiveStyle(OsmPrimitive osm, boolean nodefault) {
     70    public StyleCache getPrimitiveStyle(OsmPrimitive osm, boolean nodefault) {
    7371        if(osm.mappaintStyle == null)
    7472        {
     
    7977                }
    8078            }
    81             if (osm.mappaintStyle == null) {
     79            if (osm.mappaintStyle.equals(StyleCache.EMPTY_STYLECACHE)) {
    8280                if(osm instanceof Node)
    83                     osm.mappaintStyle = SimpleNodeElemStyle.INSTANCE;
     81                    osm.mappaintStyle = StyleCache.SIMPLE_NODE_STYLECACHE;// SimpleNodeElemStyle.INSTANCE;
    8482                else if (osm instanceof Way)
    85                     osm.mappaintStyle = LineElemStyle.UNTAGGED_WAY;
    86             }
    87         }
    88         if(nodefault && osm.mappaintStyle == LineElemStyle.UNTAGGED_WAY)
    89             return null;
     83                    osm.mappaintStyle = StyleCache.UNTAGGED_WAY_STYLECACHE;//LineElemStyle.UNTAGGED_WAY;
     84            }
     85        }
     86        if (nodefault && osm.mappaintStyle.equals(StyleCache.UNTAGGED_WAY_STYLECACHE))
     87            return StyleCache.EMPTY_STYLECACHE;
    9088        return osm.mappaintStyle;
    9189    }
    9290
    9391    public IconElemStyle getPrimitiveNodeStyle(OsmPrimitive osm) {
    94         if(osm.mappaintStyle == null && styles != null)
    95             osm.mappaintStyle = styles.getIcon(osm);
    96 
    97         return (IconElemStyle)osm.mappaintStyle;
     92        if(osm.mappaintStyle == null && styles != null) {
     93            IconElemStyle icon = styles.getIcon(osm);
     94            osm.mappaintStyle = StyleCache.create(icon);
     95            return icon;
     96        }
     97        for (ElemStyle s : osm.mappaintStyle.getStyles()) {
     98            if (s instanceof IconElemStyle)
     99                return (IconElemStyle) s;
     100        }
     101        return null;
    98102    }
    99103
     
    115119            return;
    116120
    117         ElemStyle nodeStyle = getPrimitiveStyle(n, false);
    118 
    119         if (isZoomOk(nodeStyle)) {
    120             nodeStyle.paintPrimitive(n, paintSettings, painter, data.isSelected(n),
    121             false);
     121        StyleCache sc = getPrimitiveStyle(n, false);
     122
     123        for (ElemStyle s : sc.getStyles()) {
     124            if (isZoomOk(s)) {
     125                s.paintPrimitive(n, paintSettings, painter, data.isSelected(n), false);
     126            }
     127
    122128        }
    123129    }
     
    158164            return;
    159165
    160         ElemStyle wayStyle = getPrimitiveStyle(w, false);
    161 
    162         if(!isZoomOk(wayStyle))
    163             return;
    164 
    165         if(wayStyle instanceof LineElemStyle) {
    166             wayStyle.paintPrimitive(w, paintSettings, painter, data.isSelected(w), false);
    167         } else if (wayStyle instanceof AreaElemStyle) {
    168             AreaElemStyle areaStyle = (AreaElemStyle) wayStyle;
    169             /* way with area style */
    170             if (fillAreas > dist)
    171             {
    172                 areaStyle.paintPrimitive(w, paintSettings, painter, data.isSelected(w), false);
    173             }
    174             areaStyle.getLineStyle().paintPrimitive(w, paintSettings, painter, data.isSelected(w), false);
     166        StyleCache sc = getPrimitiveStyle(w, false);
     167        for (ElemStyle s : sc.getStyles()) {
     168            if(!isZoomOk(s))
     169                return;
     170            if (fillAreas > dist || !(s instanceof AreaElemStyle)) {
     171                s.paintPrimitive(w, paintSettings, painter, data.isSelected(w), false);
     172            }
    175173        }
    176174    }
     
    369367        multipolygon.load(r);
    370368
    371         ElemStyle wayStyle = getPrimitiveStyle(r, false);
     369        AreaElemStyle areaStyle = null;
     370        LineElemStyle lineStyle = null;
     371        for (ElemStyle s : getPrimitiveStyle(r, false).getStyles()) {
     372            if (s instanceof AreaElemStyle) {
     373                areaStyle = (AreaElemStyle) s;
     374            } else if (s instanceof LineElemStyle) {
     375                lineStyle = (LineElemStyle) s;
     376            }
     377        }
    372378
    373379        boolean disabled = r.isDisabled();
    374380        // If area style was not found for relation then use style of ways
    375         if(styles != null && !(wayStyle instanceof AreaElemStyle)) {
     381        if(styles != null && areaStyle == null) {
    376382            for (Way w : multipolygon.getOuterWays()) {
    377                 wayStyle = styles.getArea(w);
     383                for (ElemStyle s : styles.getArea(w).getStyles()) {
     384                    if (s instanceof AreaElemStyle) {
     385                        areaStyle = (AreaElemStyle) s;
     386                    } else if (s instanceof LineElemStyle) {
     387                        lineStyle = (LineElemStyle) s;
     388                    }
     389                }
    378390                disabled = disabled || w.isDisabled();
    379                 if(wayStyle != null) {
     391                if(areaStyle != null) {
    380392                    break;
    381393                }
     
    383395        }
    384396
    385         if (wayStyle instanceof AreaElemStyle) {
    386             boolean zoomok = isZoomOk(wayStyle);
     397        if (areaStyle != null) {
     398            boolean zoomok = isZoomOk(areaStyle);
    387399            boolean visible = false;
    388400
     
    390402
    391403            if(zoomok && !disabled && !multipolygon.getOuterWays().isEmpty()) {
    392                 AreaElemStyle areaStyle = (AreaElemStyle)wayStyle;
    393404                for (PolyData pd : multipolygon.getCombinedPolygons()) {
    394405                    Polygon p = pd.get();
     
    399410                    boolean selected = pd.selected || data.isSelected(r);
    400411                    painter.drawArea(p, selected ? paintSettings.getRelationSelectedColor()
    401                     : areaStyle.color, painter.getAreaName(r));
     412                                : areaStyle.color, painter.getAreaName(r));
    402413                    visible = true;
    403414                }
     
    407418                return drawn;
    408419            for (Way wInner : multipolygon.getInnerWays()) {
    409                 ElemStyle innerStyle = getPrimitiveStyle(wInner, true);
    410                 if(innerStyle == null) {
     420                StyleCache inner = getPrimitiveStyle(wInner, true);
     421                AreaElemStyle innerArea = null;
     422                for (ElemStyle s : inner.getStyles()) {
     423                    if (s instanceof AreaElemStyle) {
     424                        innerArea = (AreaElemStyle) s;
     425                        break;
     426                    }
     427                }
     428
     429                if(inner.getStyles().isEmpty()) {
    411430                    if (data.isSelected(wInner) || disabled)
    412431                        continue;
    413432                    if(zoomok && (wInner.mappaintDrawnCode != paintid || multipolygon.getOuterWays().isEmpty())) {
    414                         ((AreaElemStyle)wayStyle).getLineStyle().paintPrimitive(wInner, paintSettings,
    415                         painter, (data.isSelected(wInner) || data.isSelected(r)), false);
     433                        lineStyle.paintPrimitive(wInner, paintSettings,
     434                                painter, (data.isSelected(wInner) || data.isSelected(r)), false);
    416435                    }
    417436                    wInner.mappaintDrawnCode = paintid;
    418437                }
    419                 else
    420                 {
    421                     if(wayStyle.equals(innerStyle))
    422                     {
     438                else {
     439                    if(areaStyle.equals(innerArea)) {
    423440                        wInner.mappaintDrawnAreaCode = paintid;
    424                         if(!data.isSelected(wInner))
    425                         {
     441                       
     442                        if(!data.isSelected(wInner)) {
    426443                            wInner.mappaintDrawnCode = paintid;
    427444                            drawWay(wInner, 0);
     
    431448            }
    432449            for (Way wOuter : multipolygon.getOuterWays()) {
    433                 ElemStyle outerStyle = getPrimitiveStyle(wOuter, true);
    434                 if(outerStyle == null) {
     450                StyleCache outer = getPrimitiveStyle(wOuter, true);
     451                boolean hasOuterArea = false;
     452                for (ElemStyle s : outer.getStyles()) {
     453                    if (s instanceof AreaElemStyle) {
     454                        hasOuterArea = true;
     455                        break;
     456                    }
     457                }
     458
     459                if (outer.getStyles().isEmpty()) {
    435460                    // Selected ways are drawn at the very end
    436461                    if (data.isSelected(wOuter))
    437462                        continue;
    438463                    if(zoomok) {
    439                         ((AreaElemStyle)wayStyle).getLineStyle().paintPrimitive(wOuter, paintSettings, painter,
    440                         (data.isSelected(wOuter) || data.isSelected(r)), r.isSelected());
     464                        lineStyle.paintPrimitive(wOuter, paintSettings, painter,
     465                            (data.isSelected(wOuter) || data.isSelected(r)), r.isSelected());
    441466                    }
    442467                    wOuter.mappaintDrawnCode = paintid;
    443                 } else if(outerStyle instanceof AreaElemStyle) {
     468                } else if (hasOuterArea) {
    444469                    wOuter.mappaintDrawnAreaCode = paintid;
    445470                    if(!data.isSelected(wOuter)) {
     
    512537    /* Shows areas before non-areas */
    513538    public void visitAll(final DataSet data, boolean virtual, Bounds bounds) {
     539        //long start = System.currentTimeMillis();
    514540        BBox bbox = new BBox(bounds);
    515541        this.data = data;
     
    616642                            OsmPrimitive osm = m.getMember();
    617643                            if(osm.isDrawable()) {
    618                                 ElemStyle style = getPrimitiveStyle(m.getMember(), false);
     644                                StyleCache sc = getPrimitiveStyle(m.getMember(), false);
    619645                                if(osm instanceof Way)
    620646                                {
    621                                     if(style instanceof AreaElemStyle) {
    622                                         ((AreaElemStyle)style).getLineStyle().paintPrimitive(osm, paintSettings, painter, true, true);
    623                                     } else {
    624                                         style.paintPrimitive(osm, paintSettings, painter, data.isSelected(osm), true);
     647                                    for (ElemStyle s : sc.getStyles()) {
     648                                        if (!(s instanceof AreaElemStyle)) {
     649                                            s.paintPrimitive(osm, paintSettings, painter, data.isSelected(osm), true);
     650                                        }
    625651                                    }
    626652                                }
    627653                                else if(osm instanceof Node)
    628654                                {
    629                                     if(isZoomOk(style)) {
    630                                         style.paintPrimitive(osm, paintSettings, painter, data.isSelected(osm), true);
     655                                    for (ElemStyle s : sc.getStyles()) {
     656                                        if (isZoomOk(s)) {
     657                                            s.paintPrimitive(osm, paintSettings, painter, data.isSelected(osm), true);
     658                                        }
    631659                                    }
    632660                                }
     
    648676
    649677        painter.drawVirtualNodes(data.searchWays(bbox));
     678        //System.err.println("PAINTING TOOK "+(System.currentTimeMillis() - start));
    650679    }
    651680
Note: See TracChangeset for help on using the changeset viewer.