Changeset 11779 in josm


Ignore:
Timestamp:
2017-03-25T23:34:39+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #14572 - Don't index MultipolygonCache by NavigatableComponent

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r11761 r11779  
    441441     */
    442442    public void drawArea(Relation r, Color color, MapImage fillImage, Float extent, Float extentThreshold, boolean disabled, TextLabel text) {
    443         Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r);
     443        Multipolygon multipolygon = MultipolygonCache.getInstance().get(r);
    444444        if (!r.isDisabled() && !multipolygon.getOuterWays().isEmpty()) {
    445445            for (PolyData pd : multipolygon.getCombinedPolygons()) {
     
    11291129            consumer.accept(getPath((Way) osm));
    11301130        } else if (osm instanceof Relation) {
    1131             Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) osm);
     1131            Multipolygon multipolygon = MultipolygonCache.getInstance().get((Relation) osm);
    11321132            if (!multipolygon.getOuterWays().isEmpty()) {
    11331133                for (PolyData pd : multipolygon.getCombinedPolygons()) {
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java

    r11117 r11779  
    2828import org.openstreetmap.josm.data.projection.Projection;
    2929import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
    30 import org.openstreetmap.josm.gui.NavigatableComponent;
    3130import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
    3231import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     
    4342    private static final MultipolygonCache INSTANCE = new MultipolygonCache();
    4443
    45     private final Map<NavigatableComponent, Map<DataSet, Map<Relation, Multipolygon>>> cache;
     44    private final Map<DataSet, Map<Relation, Multipolygon>> cache;
    4645
    4746    private final Collection<PolyData> selectedPolyData;
     
    6564    /**
    6665     * Gets a multipolygon from cache.
    67      * @param nc The navigatable component
    6866     * @param r The multipolygon relation
    6967     * @return A multipolygon object for the given relation, or {@code null}
    70      */
    71     public Multipolygon get(NavigatableComponent nc, Relation r) {
    72         return get(nc, r, false);
     68     * @since 11779
     69     */
     70    public Multipolygon get(Relation r) {
     71        return get(r, false);
    7372    }
    7473
    7574    /**
    7675     * Gets a multipolygon from cache.
    77      * @param nc The navigatable component
    7876     * @param r The multipolygon relation
    7977     * @param forceRefresh if {@code true}, a new object will be created even of present in cache
    8078     * @return A multipolygon object for the given relation, or {@code null}
    81      */
    82     public Multipolygon get(NavigatableComponent nc, Relation r, boolean forceRefresh) {
     79     * @since 11779
     80     */
     81    public Multipolygon get(Relation r, boolean forceRefresh) {
    8382        Multipolygon multipolygon = null;
    84         if (nc != null && r != null) {
    85             Map<DataSet, Map<Relation, Multipolygon>> map1 = cache.get(nc);
    86             if (map1 == null) {
    87                 map1 = new ConcurrentHashMap<>();
    88                 cache.put(nc, map1);
    89             }
    90             Map<Relation, Multipolygon> map2 = map1.get(r.getDataSet());
     83        if (r != null) {
     84            Map<Relation, Multipolygon> map2 = cache.get(r.getDataSet());
    9185            if (map2 == null) {
    9286                map2 = new ConcurrentHashMap<>();
    93                 map1.put(r.getDataSet(), map2);
     87                cache.put(r.getDataSet(), map2);
    9488            }
    9589            multipolygon = map2.get(r);
     
    108102
    109103    /**
    110      * Clears the cache for the given navigatable component.
    111      * @param nc the navigatable component
    112      */
    113     public void clear(NavigatableComponent nc) {
    114         Map<DataSet, Map<Relation, Multipolygon>> map = cache.remove(nc);
    115         if (map != null) {
    116             map.clear();
    117         }
    118     }
    119 
    120     /**
    121104     * Clears the cache for the given dataset.
    122105     * @param ds the data set
    123106     */
    124107    public void clear(DataSet ds) {
    125         for (Map<DataSet, Map<Relation, Multipolygon>> map1 : cache.values()) {
    126             Map<Relation, Multipolygon> map2 = map1.remove(ds);
    127             if (map2 != null) {
    128                 map2.clear();
    129             }
     108        Map<Relation, Multipolygon> map2 = cache.remove(ds);
     109        if (map2 != null) {
     110            map2.clear();
    130111        }
    131112    }
     
    140121    private Collection<Map<Relation, Multipolygon>> getMapsFor(DataSet ds) {
    141122        List<Map<Relation, Multipolygon>> result = new ArrayList<>();
    142         for (Map<DataSet, Map<Relation, Multipolygon>> map : cache.values()) {
    143             Map<Relation, Multipolygon> map2 = map.get(ds);
    144             if (map2 != null) {
    145                 result.add(map2);
    146             }
     123        Map<Relation, Multipolygon> map2 = cache.get(ds);
     124        if (map2 != null) {
     125            result.add(map2);
    147126        }
    148127        return result;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/PowerLines.java

    r11608 r11779  
    99import java.util.List;
    1010
    11 import org.openstreetmap.josm.Main;
    1211import org.openstreetmap.josm.data.osm.Node;
    1312import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2928public class PowerLines extends Test {
    3029
     30    /** Test identifier */
    3131    protected static final int POWER_LINES = 2501;
    3232
     
    106106                nodesLists.add(((Way) station).getNodes());
    107107            } else if (station instanceof Relation) {
    108                 Multipolygon polygon = MultipolygonCache.getInstance().get(Main.map.mapView, (Relation) station);
     108                Multipolygon polygon = MultipolygonCache.getInstance().get((Relation) station);
    109109                if (polygon != null) {
    110110                    for (JoinedWay outer : Multipolygon.joinWays(polygon.getOuterWays())) {
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r11774 r11779  
    750750        Main.pref.removePreferenceChangeListener(this);
    751751        DataSet.removeSelectionListener(repaintSelectionChangedListener);
    752         MultipolygonCache.getInstance().clear(this);
     752        MultipolygonCache.getInstance().clear();
    753753        if (mapMover != null) {
    754754            mapMover.destroy();
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r11730 r11779  
    8888    }
    8989
     90    /**
     91     * Returns the list of style sources.
     92     * @return the list of style sources
     93     */
    9094    public List<StyleSource> getStyleSources() {
    9195        return Collections.<StyleSource>unmodifiableList(styleSources);
     
    218222                    continue;
    219223                }
    220                 Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, r);
     224                Multipolygon multipolygon = MultipolygonCache.getInstance().get(r);
    221225
    222226                if (multipolygon.getOuterWays().contains(osm)) {
     
    286290                    continue;
    287291                }
    288                 final Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, ref);
     292                final Multipolygon multipolygon = MultipolygonCache.getInstance().get(ref);
    289293
    290294                if (multipolygon.getInnerWays().contains(osm)) {
     
    320324                    && !Utils.exists(p.a, AreaElement.class) && Main.pref.getBoolean("multipolygon.deprecated.outerstyle", true)) {
    321325                // look at outer ways to find area style
    322                 Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) osm);
     326                Multipolygon multipolygon = MultipolygonCache.getInstance().get((Relation) osm);
    323327                for (Way w : multipolygon.getOuterWays()) {
    324328                    Pair<StyleElementList, Range> wayStyles = generateStyles(w, scale, false);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java

    r11562 r11779  
    1616import java.util.regex.PatternSyntaxException;
    1717
    18 import org.openstreetmap.josm.Main;
    1918import org.openstreetmap.josm.actions.search.SearchCompiler.InDataSourceArea;
    2019import org.openstreetmap.josm.data.osm.Node;
     
    741740            return e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon() &&
    742741                    !e.osm.isIncomplete() && !((Relation) e.osm).hasIncompleteMembers() &&
    743                     !MultipolygonCache.getInstance().get(Main.map.mapView, (Relation) e.osm).getOpenEnds().isEmpty();
     742                    !MultipolygonCache.getInstance().get((Relation) e.osm).getOpenEnds().isEmpty();
    744743        }
    745744
     
    768767                return true;
    769768            if (e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon())
    770                 return MultipolygonCache.getInstance().get(Main.map.mapView, (Relation) e.osm).getOpenEnds().isEmpty();
     769                return MultipolygonCache.getInstance().get((Relation) e.osm).getOpenEnds().isEmpty();
    771770            return false;
    772771        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r11370 r11779  
    245245                public void visit(Relation r) {
    246246                    if (left.matches(e.withPrimitive(r))) {
    247                         final List<Node> openEnds = MultipolygonCache.getInstance().get(Main.map.mapView, r).getOpenEnds();
     247                        final List<Node> openEnds = MultipolygonCache.getInstance().get(r).getOpenEnds();
    248248                        final int openEndIndex = openEnds.indexOf(e.osm);
    249249                        if (openEndIndex >= 0) {
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r11664 r11779  
    533533        final Multipolygon mp = Main.map == null || Main.map.mapView == null
    534534                ? new Multipolygon(multipolygon)
    535                 : MultipolygonCache.getInstance().get(Main.map.mapView, multipolygon);
     535                : MultipolygonCache.getInstance().get(multipolygon);
    536536        Path2D path = new Path2D.Double();
    537537        path.setWindingRule(Path2D.WIND_EVEN_ODD);
     
    673673        final Multipolygon mp = Main.map == null || Main.map.mapView == null
    674674                ? new Multipolygon(multipolygon)
    675                 : MultipolygonCache.getInstance().get(Main.map.mapView, multipolygon);
     675                : MultipolygonCache.getInstance().get(multipolygon);
    676676        for (Multipolygon.PolyData pd : mp.getCombinedPolygons()) {
    677677            area += pd.getAreaAndPerimeter(Projections.getProjectionByCode("EPSG:54008")).getArea();
Note: See TracChangeset for help on using the changeset viewer.